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

Array Sort in PHP

We can sort array elements in different ways. We will try to learn different types of sorting here. Let us start with a simple sort command.

Here is the code for a simple sort.

The code is given here and the output is below that.

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



Loking for the output? Here it is

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

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

FunctionApplied OnOrder byKey Association
sortelementsforwardaltered
rsortelementsreversealtered
asortelementsforwardmaintained
arsortelementsreversemaintained
ksortkeyforwardmaintained
krsortkeyreversemaintained

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