Php array_reverse returns the array instance code in reverse order, and the array_reverse Array
The php array_reverse function returns an array with the opposite unit order. This function has two parameters. The first parameter indicates the array to be processed, and the second parameter is optional, specifying whether to retain the key name of the original array. This article describes how to use the array_reverse function through examples. For more information about the coders, see.
Basic syntax of the array_reverse function:
array array_reverse ( array $array [, bool $preserve_keys = false ] )
Array_reverse () accepts array as input and returns a new array in reverse order.
If the second parameter is set to true, the key name of the element remains unchanged; otherwise, the key name is lost.
Parameter Introduction
| Parameters |
Description |
| Array |
Required. Input array. |
| Preserve |
Optional. Specifies whether to retain the key name of the original array. Returns an array with the opposite unit order. If it is set to TRUE, the numeric key is retained. Non-numeric keys are not affected by this setting and are always retained. Possible values:
|
Return Value
Returns the inverted array.
Instance:
<?php$input = array("php", 4.0, array("green", "red"));$result = array_reverse($input);$result_keyed = array_reverse($input, true);?>
This will make $ result and $ result_keyed have the same unit, but pay attention to the key name difference. The output of $ result and $ result_keyed are:
Array( [0] => Array ( [0] => green [1] => red ) [1] => 4 [2] => php)Array( [2] => Array ( [0] => green [1] => red ) [1] => 4 [0] => php)
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.