"Volvo","b"=>"BMW","c"=>"Toyota"); print_r(array_reverse($a)); ?> ``` --- ## Definition and Usage"> "Volvo","b"=>"BMW","c"=>"Toyota"); print_r(array_reverse($a)); ?> ``` --- ## Definition and Usage" />
Easy Tutorial
❮ Php Datatypes Php Filter ❯

PHP array_reverse() Function

Complete PHP Array Reference Manual

Example

Returns the array in reversed order:

<?php
$a=array("a"=>"Volvo","b"=>"BMW","c"=>"Toyota");
print_r(array_reverse($a));
?>

Definition and Usage

The array_reverse() function returns an array in reversed order.


Syntax

Parameter Description
array Required. Specifies the array.
preserve Optional. Specifies whether to preserve the keys of the original array. <br>If set to TRUE, numeric keys are preserved. Non-numeric keys are not affected by this setting and are always preserved. <br>Possible values: true<br>false

Technical Details

Return Value: Returns the reversed array.
PHP Version: 4+
--- ---
Changelog: The preserve parameter was added in PHP 4.0.3.
--- ---

More Examples

Example 1

Outputs the original array, reversed array, and reversed array with preserved keys:

<?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);
?>

❮ Php Datatypes Php Filter ❯