array_reverse() function in php || php functions
×


array_reverse() function in php

0 329

array_reverse() function of PHP used to reverse the order of a PHP array. It is an inbuilt function of PHP.

Syntax:

array_reverse($array,$preserve);

here,

  • $array is a PHP array.
  • $preserve is a Boolean variable. It can be either TRUE or FALSE. It is an optional parameter. If its value is TRUE then it does not re-index the array.

Example 1:

<?php
$arr1=array("apple","banana","pear");
$result=array_reverse($arr1);
echo "<pre>";
print_r($result);
?>

Output:


Example 2:

<?php
$arr1=array("FRUIT1"=>"apple","FRUIT2"=>"banana","FRUIT3"=>"pear");
$result=array_reverse($arr1,FALSE);
echo "<pre>";
print_r($result);
?>

Output:


Example 3:

<?php
$arr1=array(1,2,3,4,5,6,7,8);
$result=array_reverse($arr1,false);
echo "<pre>";
print_r($result);
?>

Output:


Example 4:

<?php
$arr1=array(1,2,3,4,5,6,7,8);
$result=array_reverse($arr1,TRUE);
echo "<pre>";
print_r($result);
?>

Output:




Share:


Leave a Reply


Comments
    Waiting for your comments