PHP array_reverse()Functions
Examples
Returns an array in reverse order:
$a=array("a"=>"Volvo","b"=>"BMW","c"=>"Toyota");
print_r(array_reverse($a));
Run example »
Definition and Usage
The array_reverse() function returns an array in reverse order.
Syntax
array_reverse(array,preserve)
| Parameters | Description |
|---|---|
| array | Required. Specifies the array. |
| preserve | Optional. Specifies whether to preserve the original array's keys. If set to TRUE, numeric keys are preserved. Non-numeric keys are not affected by this setting and will always be preserved. Possible values:
|
Technical Details
| Return value: | Returns the reversed array. |
|---|---|
| PHP Version: | 4+ |
| Changelog: | preserveThe parameter was added in PHP 4.0.3. |
More Examples
Example 1
Output the original array, the reversed array, and the reversed array with original keys preserved:
$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);
Run example »
Complete PHP Array Reference Other Extensions