Home Tutorial Php Phparray PHP Array Reverse

 
 

PHP Array Reverse
Posted on: October 29, 2009 at 12:00 AM
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

Related Tags for PHP Array Reverse:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.