• PHP Video Tutorials

PHP - Function array_reverse()



Syntax

array_reverse ( $array [, $preserve_keys]  );

Definition and Usage

This function reverse the order of all the elements of a padded array.

Parameters

Sr.No Parameter & Description
1

array(Required)

It specifies an array.

2

preserve_keys(Optional)

It specifies if order of keys also has to be changed or not. By default its FALSE.

Return Values

It return an array with elements in reverse order.

Example

Try out following example −

<?php
   $input = array("a"=>"banana","b"=>"mango","c"=>"orange");
   
   print_r(array_reverse($input));
?> 

This will produce following result −

Array ( [c] => orange [b] => mango [a] => banana )
php_function_reference.htm
Advertisements