|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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; |
|
#3
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > arrays and variables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|