kworld Posted May 2, 2010 Share Posted May 2, 2010 Hey all im having a little bit of a problem again... How do i do a while loop so that it calculates the $x[0] instead of stopping when it reaches the variable in the array? $x=$myarray while ($x > 0) Thanks, Nick. Quote Link to comment https://forums.phpfreaks.com/topic/200460-looping-through-an-erray/ Share on other sites More sharing options...
Alex Posted May 2, 2010 Share Posted May 2, 2010 Huh? I'm not sure what you're asking. Can you explain it better or give us an example? Quote Link to comment https://forums.phpfreaks.com/topic/200460-looping-through-an-erray/#findComment-1051941 Share on other sites More sharing options...
kworld Posted May 2, 2010 Author Share Posted May 2, 2010 Im trying to loop through an array untill the array is empty, but when the loop stops it misses out the first value of the array $x[0]. Im looping through the array backwards with this but i basically need it to read the value $x[0] before it stops. $x=$myarray while ($x > 0) Quote Link to comment https://forums.phpfreaks.com/topic/200460-looping-through-an-erray/#findComment-1051945 Share on other sites More sharing options...
kworld Posted May 2, 2010 Author Share Posted May 2, 2010 problem solved i just started inputting the array contents from $x[1]. Is this a lasy way and is there a proper way of doing it? Quote Link to comment https://forums.phpfreaks.com/topic/200460-looping-through-an-erray/#findComment-1051947 Share on other sites More sharing options...
Alex Posted May 2, 2010 Share Posted May 2, 2010 You mean something like this? $x = sizeof($arr); while($x > 0) { --$x; echo $arr[$x]; } Quote Link to comment https://forums.phpfreaks.com/topic/200460-looping-through-an-erray/#findComment-1051951 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 $x = sizeof($arr); while(--$x > 0) echo $arr[$x]; Quote Link to comment https://forums.phpfreaks.com/topic/200460-looping-through-an-erray/#findComment-1051971 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.