Jump to content

Archived

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

earl_dc10

while() arrays

Recommended Posts

hey, I've never had much contact with arrays up to this point, always found a different way, but this time, they caught up to me.
Im trying to insert an array key ($x) and an array value ($result_select) for every time a while loop runs and then print_r the whole array (with all the $x's and $result_select's in their respective places). As I said I've never had much luck with arrays and there's probably a very simple answer to this, but hey, ya learn something new every day!

Thanks
-J

Share this post


Link to post
Share on other sites
something like this should do what you're asking for, unless I'm misunderstanding you.

[code]<?php
$var = array();
while($x < 10)
{
    $var[$x] = $result_select;
    $x++; //to prevent an infinite loop!
}

print_r($var);
?>[/code]

Share this post


Link to post
Share on other sites
hey, thanks, wow, that was a simple answer.... oh well, I got a lot to learn about arrays, thanks again!

Share this post


Link to post
Share on other sites
There is a simpler way:
[code]<?php
$var = array();
for ($x=0;$x<10;$x++)
    $var[$x] = $result_select;

echo '<pre>'.print_r($var,true).'</pre>'; // prints better on the screen
?>[/code]

Ken

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.