X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP array_reverse() Function

PHP Array Reference PHP Array Reference

Example

Return an array in the reverse order:

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

Run example »

Definition and Usage

The array_reverse() function returns an array in the reverse order.


Syntax

array_reverse(array,preserve)

Parameter Description
array Required. Specifies an array
preserve Optional. Specifies if the function should preserve the keys of the array or not.

Possible values:
  • true
  • 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

Return the original array, the reversed array and the preserved array:

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

Run example »


PHP Array Reference PHP Array Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook