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

Array asort

We can use the array sorting function asort to arrange the array elements alphabetical order. Here by using assort function we can retain or maintain the index association of each element. This can be easily explained by this example. Here is the code and the output is given below that.

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

Here is the output

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

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

Be the first to post comment on this article :


Google+
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