SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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



Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
Array Functions
PHP Sections