PHP Array Reverse


 

PHP Array Reverse

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

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

Ads