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']);

Official PHP 8 documentation

More strings and arrays commands

All strings and arrays commands · PHP 8 cheatsheet

Was this page helpful?