View Full Version : Help me on how to echo array_reverse in php

01-11-2012, 01:36 PM
Hi ,
I am writing a code which i want to echo it out and see the output rather than print_r,

can someone help me out
Here is the code




Clement Ose

01-11-2012, 04:24 PM
I use a for loop but I'm a C progarmmer. If there is an easier way I'd like to know. But this should work...

$count = count($array_r);

for($i = 0; $i = ($count - 1); $i++){
echo $array_r[$i];

01-11-2012, 04:34 PM

foreach() loop would work as well:

foreach ( $array as $value )
echo $value, "<br /><br />\n";

foreach ( $array as $key => $value )
echo $key , "<br />\n";
echo $value, "<br /><br />\n";

01-11-2012, 04:35 PM
Along the lines of the for loop there are multiple ways to do this e.g. using foreach (as shown), a while loop

while(list($key,$value) = each($array_r))
echo $value.'<br>';
each returns key=>value pairs which is why I have them in the for loop.