Monday 26 August 2013

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.

Paramters

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 )

No comments:

Post a Comment