PHP 8 · Strings and arrays
Sort with a comparison
Sort an array by a field using the spaceship operator.
usort($users, fn ($a, $b) => $a['age'] <=> $b['age']);
PHP 8 · Strings and arrays
Sort an array by a field using the spaceship operator.
usort($users, fn ($a, $b) => $a['age'] <=> $b['age']);
Was this page helpful?