Reverse Sort using rsort |
We can sort an array in reverse order of sort function by using rsort command. Here the index associated with each element is not retained. This is the only difference between rsort and arsort commands.
Here is the example code.
<?
$input = array ("Pinaple", "Orange", "Banana", "Mango", "Apple","Strawberry");
while (list ($key, $val) = each ($input)) {
echo "$key -> $val <br>";
}
rsort($input);
echo "<br>-----After rsort---------<br>";
while (list ($key, $val) = each ($input)) {
echo "$key -> $val <br>";
}
?>
Here is the output of rsort function
0 -> Pinaple 1 -> Orange 2 -> Banana 3 -> Mango 4 -> Apple 5 -> Strawberry -----After rsort--------- 0 -> Strawberry 1 -> Pinaple 2 -> Orange 3 -> Mango 4 -> Banana 5 -> Apple
|