SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Basic For Loop Help

    Hi Guys,

    I have a general enquiry about PHP syntax. I'm having trouble creating a VERY simple for loop using PHP, i think the best way to explain this is by an example:
    say if i want to create a loop which changes the values of different variables of incrementing names at every loop, how would i do this:

    $date1 = sunday
    $date2 = monday
    $date3 = tuesday
    ... $date7 = saturday

    for ($i=1; $i<8; $i++) {
    $date.$i==1;
    }

    the above code doesnt work, i hope you guys can see what im trying to do here.
    trying to amend $date1 == 1, then $date2 == 1... $date7== 1.

    What should be the correct code for $date.$i==1?

    Thanks,
    - Justin

  2. #2
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $concatenatedDate 'date'.$i;
    $
    $concatenatedDate == 1
    OR

    PHP Code:
    ${'date'.$i} == 1
    I haven't ever tried the latter but I think that should work, try the second piece of code first, if it works well n good, if not the pirst piece will surely work.

    Edit:


    I just tested the latter, it works too, so now its upto you


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •