Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP array_reverse() Function

PHP array_reverse() Function

PHP Array ReferenceComplete 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 会保留数字的键。 非数字的键则不受这个设置的影响,总是会被保留。       
 可能的值:     
  • true
  • false
  • |

    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 »


    PHP Array ReferenceComplete PHP Array Reference Manual