Example
Return the array in reversed order:
<?php $a=array("a"=>"Volvo","b"=>"BMW","c"=>"Toyota"); print_r(array_reverse($a)); ?>
Definition and usage
array_reverse() FunctionReturn the flip Sequential array.
Syntax
array_reverse(array,preserve)
Parameters | Description |
array | Required. Specifies an array. |
preserve | Optional. Specifies whether to retain the original array key names. If set to TRUE, numeric keys will be preserved. Non-numeric keys are not affected by this setting and will always be retained. Possible values:
|
Technical details
Return value: | Returns the flipped array. |
PHP Version: | 4+ |
##Update Log : | The preserve parameter isnew in PHP 4.0.3. |
<?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); ?>
<?php $input = array("php", 4.0, array("green", "red")); $result = array_reverse($input); $result_keyed = array_reverse($input, true); ?>
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 the detailed content of php function array_reverse() that returns an array in reverse order. For more information, please follow other related articles on the PHP Chinese website!