sort array of arrays 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: php sort multidimensional array
array_multisort(array_map(function($element) {
return $element['order'];
}, $array), SORT_ASC, $array);
print_r($array);
Example 3: sort multi array php
$keys = array_column($array, 'Price');
array_multisort($keys, SORT_ASC, $array);
print_r($array);
Example 4: php sort()
<?php
$fruits = array("Zitrone", "Orange", "Banane", "Apfel");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
Example 5: php array sort
function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}