|
|
|
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.
<?
$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
| |
|
| Array Functions |
|
|
|
| PHP Sections |
|
|
|