zolen Posted November 22, 2007 Share Posted November 22, 2007 Hello, have been trying to nut this out for a bit now, I am fairly sure its a syntax issue but then I am using the same logic to say that is I did to write the code .. which could also be completly wrong. (basically...I could be an idot ) Anyhow let me show you the code: $im_in_a_loop=0; while($im_in_a_loop<5)//the actual script is much more complex but this should display the issue } $im_in_a_loop++; $im_an_array_in_a_loop = array($im_in_a_loop); } $array_reversed_out_of_loop = array_reverse($im_an_array_in_a_loop); foreach($array_reversed_out_of_loop as $char) echo $char; //the answer I am looking for is 5 4 3 2 1 Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 22, 2007 Share Posted November 22, 2007 $some_array = null; for($i=5;$i>0;$i--){ $some_array[] = $i; } foreach($some_array as $number){ echo $number." "; } Would be the way of doing it.. however.. this is shorter for($i=5;$i>0;$i--){ echo $i." "; } Quote Link to comment Share on other sites More sharing options...
zolen Posted November 22, 2007 Author Share Posted November 22, 2007 wow thanks for the quick reply, unfortunatly I do not have the option of changing how the variable enters the array but only how it exits hence the array_reverse. The reason I wrote it like that was to simplify a bit of code that is allready in use .. however the variable has simply been echoed within the loop, I need to put it into an array and reverse the order then echo/print. Quote Link to comment Share on other sites More sharing options...
trq Posted November 22, 2007 Share Posted November 22, 2007 Sorry, what exactly is your question? Quote Link to comment Share on other sites More sharing options...
zolen Posted November 22, 2007 Author Share Posted November 22, 2007 hehe .. well I cant seem to echo anything at the end. either the array isnt working or the reverse isnt working or the foreach isnt working ... was hoping that someone would see the code and say "OMG thats soo simple ... and tell me that I have put a . where a : should be .. or something like that Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 22, 2007 Share Posted November 22, 2007 Well, I think it's this line: $im_an_array_in_a_loop = array($im_in_a_loop); In which $im_an_array_in_a_loop is basically an array containing the first element only... If you want to keep adding more vales into the array, make it: $im_an_array_in_a_loop[] = $im_in_a_loop; Quote Link to comment Share on other sites More sharing options...
zolen Posted November 22, 2007 Author Share Posted November 22, 2007 YAY kratsg is my hero Thanks soo much wow and solved within 32 minutes. Thanks to thorpe as well for looking in 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.