earl_dc10 Posted March 6, 2006 Share Posted March 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/4184-while-arrays/ Share on other sites More sharing options...
neylitalo Posted March 6, 2006 Share Posted March 6, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/4184-while-arrays/#findComment-14542 Share on other sites More sharing options...
earl_dc10 Posted March 6, 2006 Author Share Posted March 6, 2006 hey, thanks, wow, that was a simple answer.... oh well, I got a lot to learn about arrays, thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/4184-while-arrays/#findComment-14551 Share on other sites More sharing options...
kenrbnsn Posted March 6, 2006 Share Posted March 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/4184-while-arrays/#findComment-14553 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.