PHP - Function array_reverse()


Advertisements


Syntax

array_reverse ( $array [, $preserve_keys]  );

Definition and Usage

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

Parameters

ParameterDescription
arrayRequired. Specifies an array.
preserve_keysOptional. Specifies if order of keys also has to be changed ofr not. By default its FALSE.

Return Values

Return an array with elements in reverse order.

Example

Try out following example:

<?php
$array=array("a"=>"banana","b"=>"apple","c"=>"orange");

print_r(array_reverse($array));
?> 

This will produce following result:

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

php_function_reference.htm

Advertisements