Sorting
sort and rsort sort values, asort and arsort keep keys, ksort sorts by key and usort uses your function.
Example
$a = [3, 1, 2];
sort($a); echo implode(",", $a), "\n";
$p = ["b" => 2, "a" => 3];
ksort($p); print_r($p);
usort($a, fn($x, $y) => $y <=> $x);
echo implode(",", $a);Result
1,2,3
Array
(
[a] => 3
[b] => 2
)
3,2,1Exercise
Sort by key.
($p)Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.