Array_reverse (returns an array of cells in reverse order)
Applicable (PHP 4, PHP 5)
Description
array_reverse ( array $array
[, $preserve _keys
Array_reverse () accepts an array array
as input and returns a new array of cells in reverse order.
Parameters:
return value: Array ()
Returns the inverted array.
Example:
Example #1 Array_reverse () example
<?php
$input= Array ("PHP", 4.0, Array ("Green", "Red"));
$result= Array_reverse($input);
$result _keyed= Array_reverse($input, true);
?>
This will make $result and $result_keyed have the same unit, but note the difference between the key names.
$resultAnd $result_keyed The printout displays are:
Array ([0] = = Array ([0] = green [1] = + red) [1] = 4 [2] => ; PHP) Array ([2] = = Array ([0] = green [1] = + red) [1] = 4 [0] = PHP)
Rsort (reverse sequence of an array)
Applicable (PHP 4, PHP 5)
Description
BOOL Rsort ( array &$array
[, int $sort_flags
= Sort_regular ] )
This function reverses the order of the array (highest to lowest).
Parameters:
return value:
Returns when successful TRUE
, or on failure FALSE
.
Example:
Example #1 Rsort () example
<?php
$fruits= Array ("Lemon", "Orange", "Banana", "Apple");
Rsort($fruits);
foreach ($fruits as$key=$val) {
Echo"$key = $val\ n ";
}
?>
The above routines will output:
0 = Orange1 = Lemon2 = Banana3 = Apple
* Note: Fruits are sorted in alphabetical order.
Comments:
Note: This function array
assigns the new key name to the element in. This will delete the original key name instead of just reordering the key name.
This article from "I am a phper, simple and naïve" blog, please be sure to keep this source http://thinkforphp.blog.51cto.com/8733331/1784646
PHP-Array Reverse