Sort functions work in place, and their names encode their behavior: a keeps key associations, k sorts by key, r reverses, and u takes a comparator returning a negative, zero or positive int, as <=> does (Spaceship and Ternary). natsort() puts img2 before img10.
<?php
$books = [['Dune', 9.99], ['Emma', 4.5], ['Ariel', 9.99], ['Odes', 4.5], ['Beowulf', 12.0]];
usort($books, fn(array $x, array $y): int => $x[1] <=> $y[1]); // ties keep input order
echo implode(', ', array_column($books, 0)), "\n";
$prices = ['BK-300' => 12.0, 'BK-101' => 9.99, 'BK-205' => 4.5];
$p = $prices; sort($p); echo json_encode($p), ' '; // keys discarded
$p = $prices; asort($p); echo json_encode($p), "\n"; // keys kept
$f = ['img12.png', 'img10.png', 'IMG2.png', 'img1.png'];
sort($f, SORT_NATURAL | SORT_FLAG_CASE); echo implode(' ', $f), "\n";
$r = [['t' => 'Emma', 'p' => 4.5], ['t' => 'Dune', 'p' => 9.9], ['t' => 'Ariel', 'p' => 9.9]];
array_multisort(array_column($r, 'p'), SORT_DESC, array_column($r, 't'), $r);
echo implode(', ', array_column($r, 't')), "\n"; // ORDER BY p DESC, t ASCEmma, Odes, Dune, Ariel, Beowulf
[4.5,9.99,12] {"BK-205":4.5,"BK-101":9.99,"BK-300":12}
img1.png IMG2.png img10.png img12.png
Ariel, Dune, EmmaSince PHP 8.0 sorting is stable: equal elements keep their input order, so Emma stays before Odes. Flags such as SORT_NATURAL | SORT_FLAG_CASE change the comparison, and array_multisort() sorts by several columns, like ORDER BY p DESC, t ASC, reordering the last array to match. A comparator returning a bool ($x > $y) has raised a deprecation since PHP 8.0, because it cannot report "equal"; return <=>, and let MySQL 524 's ORDER BY sort rows before they reach PHP.