sort array in ascending order php code example
Example 1: sort array of array php
sort()
rsort()
asort()
ksort()
arsort()
krsort()
$array = array(1, 3, 2);
sort($array)
Example 2: sort array php
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
asort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
c = apple
b = banana
d = lemon
a = orange
Example 3: array sort php
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo $val;
}
?>
Example 4: php sort()
<?php
$fruits = array("Zitrone", "Orange", "Banane", "Apfel");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>