whittierpc Posted August 22, 2006 Share Posted August 22, 2006 how would I get a value to be set in an array inside a while loop and when it looped the second and third time thos values would be the second and third values of the array?Many Thank! Link to comment https://forums.phpfreaks.com/topic/18253-setting-array-values-inside-a-while-loop/ Share on other sites More sharing options...
ToonMariner Posted August 22, 2006 Share Posted August 22, 2006 $val = array();while (YOUR CLAUSE){ $val[] = $x;} Link to comment https://forums.phpfreaks.com/topic/18253-setting-array-values-inside-a-while-loop/#findComment-78372 Share on other sites More sharing options...
Jeremysr Posted August 22, 2006 Share Posted August 22, 2006 A better way is to do it in a for loop:[code=php:0]for ($x = 0; $x <= 10; $x++) { $arrayname[$x] = $x;}[/code]What this would do is store all the numbers from 0 to 10 in the array, but I'm sure you'll figure it out for whatever you're trying to do. Link to comment https://forums.phpfreaks.com/topic/18253-setting-array-values-inside-a-while-loop/#findComment-78373 Share on other sites More sharing options...
ToonMariner Posted August 22, 2006 Share Posted August 22, 2006 the for loop requires you know how many variables you want to put in the array...and the while loop is the simplest most efficient loop in php.SO IMO the for loop is inferior in this case. Link to comment https://forums.phpfreaks.com/topic/18253-setting-array-values-inside-a-while-loop/#findComment-78379 Share on other sites More sharing options...
Jeremysr Posted August 22, 2006 Share Posted August 22, 2006 Ok I was kind of thinking of when you use a for loop to loop through an array printing out each value in the array or something...but I guess he doesn't want to do that. Link to comment https://forums.phpfreaks.com/topic/18253-setting-array-values-inside-a-while-loop/#findComment-78384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.