English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_reverse() Function Usage and Example

PHP Array Function Manual

The PHP array_reverse() function returns an array with the elements in reverse order

Syntax

array_reverse ( $array [, $preserve_keys]  );

Definition and Usage

The array_reverse() function accepts an array as input and returns a new array with the elements in reverse order.

Parameter

Serial NumberParameters and Description
1

array(Required)

It specifies an array.

2

preserve_keys(optional)

It specifies whether the order of the keys must also be changed. The default is FALSE.

Return Value

It returns the reversed array.

Online Example

Reverse the order of the specified array

<?php
   $input = array("a"=>"banana","b"=>"mango","c"=>"orange");
   
   print_r(array_reverse($input));
?>
Test and See‹/›

Output Result

Array ( [c] => orange [b] => mango [a] => banana )

 PHP Array Function Manual