Jump to content

Archived

This topic is now archived and is closed to further replies.

whittierpc

setting array values inside a while loop

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.