array_reverse() is an inbuilt function of PHP used to reverse the array including the nested arrays. It returns the reversed array. But in the case of associative arrays of if you don't want to change the keys of the array, $key_preserve=true can be passed as a parameter to the array_reverse() function. array_reverse() function is explained below with an example.

SYNTAX:

array array_reverse($array,$key_preserve);

$array: This parameter is mandatory and it is the array you want to
            reverse.
$key_preserve: This parameter is optional, if you set it to true then it will preserve the keys. Default value of $key_Preserve is taken as false.

EXAMPLE:
 


<?php

echo "Case 1:<br /><br />";

//Let's take an example of a linear array
$array=array(1,2,3,4,5);


//Applying array_reverse() on the above array
$array=array_reverse($array);
print_r($array);


echo "<br /><br />Case 2:<br /><br />";


//Let's use the key_preserve as true 
$array=array(1,2,3,4,5);

//key_preserve=true will preserve the keys of the array
$array=array_reverse($array,$key_preserve=true);
print_r($array);


echo "<br /><br />Case 3:<br /><br />";

//Let's take an example of nested array
$array=array(
           array(1,2,3,4,5),
           array(6,7,8,9,10),
       );

$array=array_reverse($array);

//After reversing array[0] starts with 6
print_r($array[0]);
echo "<br /><br />";

//After reversing array[1] starts with 1
print_r($array[1]);

?>

OUTPUT:
 

 

PHP