SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP Array

Array arsort to sort in reverse

See the asort array function first. The function arsort changes the elements and arrange them in reverse alphabetical order. Here in arsort the order is just opposite than asort.

By using arsort function we can retain the index or indices associated with elements of the original array.

Here is the example code. We have only changed the function asort to arsort.

<?Php
$input = array ("Pinaple", "Orange", "Banana", "Mango", "Apple","Strawberry");
while (list ($key, $val) = each ($input)) {
echo "$key -> $val <br>";
}
arsort($input);
echo "<br>-----After arsort---------<br>";
while (list ($key, $val) = each ($input)) {
echo "$key -> $val <br>";
}
?>

Here is the output of arsort function

0 -> Pinaple
1 -> Orange
2 -> Banana
3 -> Mango
4 -> Apple
5 -> Strawberry

-----After arsort---------
5 -> Strawberry
0 -> Pinaple
1 -> Orange
3 -> Mango
2 -> Banana
4 -> Apple

Number of User Comments : 1


Google+
Bilal Yunus Jawarneh04-11-2009
it is very human view that you help others by displaying your Knowledge
so thanX
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



HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer