usort()
function
Sorts array in place using a user-defined comparison function. Use the spaceship operator <=> for concise comparisons.
Syntax
usort(array &$array, callable $callback): true
Example
php
<?php
$products = [
['name'=>'Banana','price'=>1.50],
['name'=>'Apple', 'price'=>0.99],
['name'=>'Cherry','price'=>3.00],
];
usort($products, fn($a, $b) => $a['price'] <=> $b['price']);
// sorted by price ascending