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! Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 22, 2006 Share Posted August 22, 2006 $val = array();while (YOUR CLAUSE){ $val[] = $x;} Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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.