PHP Array Reverse

This PHP Tutorial section, we demonstrates you how to reverse the given array in PHP.

 
 

Share on Google+Share on Google+

PHP Array Reverse

Ads

This PHP Tutorial section, we demonstrates you how to reverse the given array in PHP.

  • Php array is reversed by the function array_reverse().
  • array_reverse() function input an array
  • Then it returns a new array with all elements reversed.


PHP Array Reverse Example

<?php
    $arr
=array("car","scooter","motorcycle","truck","cycle");
    echo
"array values are<br>";
    foreach
($arr as $a)
    echo
" ".$a;
    echo
"<br>array values after reversing are <br>";

    $arr1=array_reverse($arr);
    foreach
($arr1 as $a)
    echo
" ".$a;
?>
Output

array values are
car scooter motorcycle truck cycle
array values after reversing are
cycle truck motorcycle scooter car

Advertisements

Posted on: October 29, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles