array_reverse

array array_reverse(array array) 

Returns a copy of the original array in reverse order.

Returns:

Array in reverse order from the input array; NULL on failure

Description:

Creates a copy of the given array in reverse order, with key/value relationships intact. It returns the copy while leaving the original array untouched.

Version:

PHP 4 since 4.0b4

Example:

Reverse the order of an array’s elements
$ax = array('a' => 'alpha', 'b' => 'bravo', 'c' => 'charlie', 'd' => 'delta'); 
$reversed = array_reverse($ax); 
print_r($reversed); 

Output: 
Array 
(
    [d] => delta 
    [c] => charlie 
    [b] => bravo 
    [a] => alpha 
) 

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.