PHP » Arrays » array_reverse()

Syntax:
array array_reverse(array array [, bool leave_keys])
array
Array to be reversed.
leave_keys
Whether to preserve keys.

Reverses the order of the elements in an array.

array_reverse() returns a new array with the elements from the input array in reverse order. As of PHP 4.0.3, an optional parameter can specify that the keys should be preserved. By default they are not preserved.

Examples

Code:
<?php

$array1 = array("a", "b", "c");

foreach (array_reverse($array1) as $element) {
   print "$element ";
}

?>
Output:
c b a
Explanation:

array_reverse() is used to reverse an array.

See Also: