Home Tutorial Php Phparray PHP Array Reverse

 
 

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

Advertisement

Related Tags for PHP Array Reverse:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 29, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com