PHP array_reverse() function

PHP array_reverse() function is used to reverse the order of the elements in an array.  PHP array_reverse() function is PHP built-in function.

Syntax :

array_reverse (array $array , bool $preserve_keys = false);

Parameter,

$array : Required. It is input array.

$preserve_keys : Optional. Default value is false. If it set to true, numeric keys are preserved.

Return : It returns reversed array.

Let's see below example to understand php array_reverse() Function in details.

 

 

Example :

<?php
$array = array("php","html","css","java","mysql","asp","oracle");
$reversed_array = array_reverse($array );
echo "<br>Look at below array before reversing array<br>";
print_r($array);

echo "<br>Look at below array after reversing array<br>";
print_r($reversed_array );

echo "<br>Look at below array after reversing array where preserve_keys set to true<br>";
$preserved_array = array_reverse($array,true); //Numeric keys are preserved
print_r($preserved_array );
?>

Output :

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

89344