Return an array in reverse order:
<?php $a = array ( " a " => " Volvo " , " b " => " BMW " , " c " => " Toyota " ) ; print_r ( array_reverse ( $a ) ) ; ?>The array_reverse() function returns an array in reversed order.
array_reverse( array,preserve )
parameter | describe |
---|---|
array | Required. Specifies an array. |
preserve | Optional. Specifies whether to retain the key names of the original array. 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: true false |
Return value: | Returns the flipped array. |
---|---|
PHP version: | 4+ |
Update log: | The preserve parameter is new in PHP 4.0.3. |
Output the original array, flipped array, and flipped array retaining 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 ) ; ?>