#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    4
    Rep Power
    0
    if i am trying to make a variable $day_' . $i . ' and i have $i in a for ($1=1;$i<31; ++$i) - how do i get the variable $day_ to have the $i variable on the end? (the above doesnt work btw)

    I want to be able to have
    $day_1 = Monday
    $day_2 = Tuesday etc. Kinda thing - where i dont have to define 1,2,3,4
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    I think what your after is:
    $day."_".$i
  4. #3
  5. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Um, I think you should use an array.

    Curious, are you learning PHP after learning flash?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Pune, Maharashtra, India
    Posts
    86
    Rep Power
    15
    Try something like this :
    $day_1="Monday";$day_2="blah blah";
    for($i=0;$i<31;++$i)
    {
    $n_day="day_".$i;
    echo $$n_day;
    }
    You wil not have to defin 1234 i.e for sure.

    ------------------
    Nikunj
    MYSQL/PHP/XML
    ** Expertise comes with experiece ** Nikunj
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Helden,Limburg,The Netherlands
    Posts
    33
    Rep Power
    16
    You can have a variable in a variable by using the following syntax:

    $$day

    The variable $day could then be defined as follows:

    for ($i=0;$i<30;$i++){
    $day = "day_$i;
    $$day = "something";
    }

    I hope this is what you need,

    Good luck,
    Ramon.


    ------------------
    Ramon Litjens
    Boradoli Web Design
    (www.boradoli.nl)
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    4
    Rep Power
    0
    Thank you kindly all
    I tried almost identical code to the one you suggested Ramon, but it didnt work. In the end i couldnt use the variable variable for what i wanted to do, but i do greatly appreciate your time.
    Rod, if you mean Lingo, the Director language - yups i have learnt that also - has been a while though - not sure how it was relevant to the way i had tried to explain what i was trying to achieve though ...
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    24
    Rep Power
    0
    Can't you use the eval() function to do this?


    for($i=0;$i<31;++$i)
    {
    eval ("$day_$i="Monday";");
    echo $day_1;
    }


    That should work to create the variable.

    ------------------
    Aoeex,

    -http://www.aoeex.com

Similar Threads

  1. A variable $_POST variable?
    By CLuver in forum PHP Development
    Replies: 0
    Last Post: February 11th, 2004, 01:55 AM
  2. How to read multiple line text file into a variable
    By gatewaycityca in forum Visual Basic Programming
    Replies: 4
    Last Post: January 29th, 2004, 01:26 PM
  3. Using the echo tag to integrate a PHP variable into Javascript
    By spayce_girl in forum JavaScript Development
    Replies: 5
    Last Post: December 27th, 2003, 06:42 PM
  4. Need help with Selection Sort
    By iNspirito in forum C Programming
    Replies: 21
    Last Post: November 29th, 2003, 03:47 AM
  5. Replies: 5
    Last Post: November 16th, 2003, 12:31 PM

IMN logo majestic logo threadwatch logo seochat tools logo