PHP array_reverse() 函数
PHP array_reverse() function
Instance
<?php Return the array in the opposite order of elements: $a=array("a"=>"Volvo","b"=>"BMW","c"=>"Toyota");print_r(array_reverse($a) ?>
);
Definition and Usage
The array_reverse() function returns the array in the opposite order of elements.
Description
The array_reverse() function reverses the order of elements in the original array, creates a new array, and returns it.
If the second parameter is specified as true, the element key names remain unchanged, otherwise the key names will be lost.
Syntaxarrayarray_reverse(preserve,
) | Description |
---|---|
array | Required. Specifies the array. |
preserve |
Optional. Specifies whether to retain the original array key names. This parameter is a new addition in PHP 4.0.3. Possible Values:
|
Technical Details
Return Value: | Return the reversed array. |
PHP Version: | 4+ |
Update Log: | Added in PHP 4.0.3 preserve Parameters. |
More Examples
Example 1
Return the original array, reverse the array, and return the reversed array with the original array key names:
<?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); ?>