PHP - Function array_reverse()


Advertisements


Syntax

array_reverse ( $array [, $preserve_keys]  );

Definition and Usage

This function reverse the order of all the elements of a padded array.

Parameters

Parameter Description
array Required. Specifies an array.
preserve_keys Optional. Specifies if order of keys also has to be changed or not. By default its FALSE.

Return Values

Return an array with elements in reverse order.

Example

Try out following example −

<?php
   $array=array("a"=>"banana","b"=>"apple","c"=>"orange");
   
   print_r(array_reverse($array));
?> 

This will produce following result −

Array ( [c] => orange [b] => apple [a] => banana )

php_function_reference.htm