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

    Join Date
    Mar 2000
    Posts
    3
    Rep Power
    0
    Hello to All,
    I'm stuck and I need your assistance(if I may).

    OK here goes:
    $i=1; while ($i <= 5) { echo("$i,"); $mylink=("$i"); $i++; }

    Here is the problem. If I echo the $i string, I get 1,2,3,4,5 as a result,
    which is exactly what I should get.
    BUT... if I assign $mylink to the $i variable and I try echoing $mylink, only the last number of $i is printed. I would like to make it so the assigned variable $mylink will print the same contents as the $i.
    Thanks
    Regards, Tom...


  2. #2
  3. 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
    I'm not sure what you're asking here. Each iteration of the loop reassigns $mylink to the current value of $i so it follows that it would contain the last value of $i in the iteration. Each time you are echoing $i it is only printing the current value followed by a comma. $i NEVER equals 1,2,3,4,5 which is what you seem to imply.

    Perhaps this is what you want (BTW, please break your code up into something legible)

    $mylink="";
    for ($i=1;$i<=5;$i++)
    {
    $mylink.="$i,";
    }
    print $mylink;
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    3
    Rep Power
    0
    Rod, thank you for your immediate response.
    It worked like a charm...
    Regards,
    Tom
    ps.I will try to make my code
    more legible next time.

Similar Threads

  1. Passing arrays to function
    By aiya in forum HTML Programming
    Replies: 1
    Last Post: December 19th, 2003, 12:35 PM
  2. Checkboxes, Arrays, & session variables
    By hallik in forum ASP Programming
    Replies: 6
    Last Post: December 15th, 2003, 02:02 AM
  3. Turning arrays to variables
    By binary in forum PHP Development
    Replies: 2
    Last Post: December 6th, 2003, 11:44 AM
  4. Variables + Script Efficiency
    By peenie in forum PHP Development
    Replies: 2
    Last Post: November 17th, 2003, 11:55 PM
  5. iterating through Hash of Arrays
    By lunatic in forum Perl Programming
    Replies: 2
    Last Post: September 7th, 2003, 01:16 PM

IMN logo majestic logo threadwatch logo seochat tools logo