Return an array in the reverse order:
<?php
$a=array("a"=>"Volvo","b"=>"BMW","c"=>"Toyota");
print_r(array_reverse($a));
?>
Try it Yourself »
The array_reverse() function returns an array in the reverse order.
array_reverse(
array, preserve)
Parameter | Description |
---|---|
array | Required. Specifies an array |
preserve | Optional. Specifies if the function should preserve the keys of the array or not. Possible values:
|
Return Value: | Returns the reversed array |
---|---|
PHP Version: | 4+ |
PHP Changelog: | The preserve parameter was added in PHP 4.0.3 |
Return the original array, the reversed array and the preserved array:
<?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);
?>
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!