PHP array_reverse() Function
Complete PHP Array Reference Manual
Example
Return an array in reverse order:
" 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 keys of the original array. |
如果设置为 TRUE 会保留数字的键。 非数字的键则不受这个设置的影响,总是会被保留。
可能的值:
Technical Details
| Return Value: | Returns the reversed array. |
|---|---|
| PHP Version: | 4+ |
| Changelog: | preserve This parameter was added in PHP 4.0.3. |
More examples
Example 1
Output the original array, the reversed array, and the reversed array with the original keys preserved:
Run Example »
Complete PHP Array Reference Manual