Home Menu

array_reverse

Return an array with elements in reverse order

Syntax

array_reverse ( array $array [, bool $preserve_keys = FALSE ] ) : array

Parameters

array

The input array.

preserve_keys

If set to TRUE numeric keys are preserved. Non-numeric keys are not affected by this setting and will always be preserved.

Return

Returns the reversed array.

Examples

array | Indexed

<?

$array  = array(0, 1, array(2, 3));

$return = array_reverse($array);

print_r($return);

?>

			

		

array | Associative

<?

$array  = array("a" => 0, "b" => 1, "c" => array("d" => 2, "e" => 3));

$return = array_reverse($array);

print_r($return);

?>
NULL

preserve_keys | Indexed

<?

$array  = array(0, 1, array(2, 3));
$preserve_keys = true;

$return = array_reverse($array, $preserve_keys);

print_r($return);

?>

			

		

preserve_keys | Associative

<?

$array  = array("a" => 0, "b" => 1, "c" => array("d" => 2, "e" => 3));
$preserve_keys = true;

$return = array_reverse($array, $preserve_keys);

print_r($return);

?>
Array
(
    [a] => 0
    [c] => 2
)

PHP

JesusBible
HTMLCSSJSPHPSVGMore
AboutTerms