Return an array with its elements in reverse order.
<?php $a=array(“a”=>“Volvo”,“b”=>“BMW”,“c”=>“Toyota”); print_r(array_reverse($a)); ?> |
The array_reverse() function returns an array with its elements reversed.
array_reverse(array, preserve) |
Parameter |
Description |
array |
Required. Specifies the array to be reversed. |
preserve |
Optional. Indicates whether the function should preserve the array keys. Possible values are:
|
Return Value: |
Returns the array with elements in reverse order. |
PHP Version: |
4+ |
PHP Changelog: |
The |
Return the original array, the reversed array, and the array with preserved keys.
<?php $a=array(“Volvo”,“XC90”,array(“BMW”,“Toyota”)); $reverse=array_reverse($a); $preserve=array_reverse($a,true); print_r($a); print_r($reverse); print_r($preserve); ?> |