// *** before: ***
function compareOld($a, $b) {
if ($a == $b) {
return 0;
}
return $a < $b ? -1 : 1;
}
$items = [3, 1, 2];
usort($items, 'compareOld');
// *** in version 7.0: ***
$items = [3, 1, 2];
usort($items, function ($a, $b) {
return $a <=> $b;
});
var_dump($items); // [1, 2, 3]
echo 1 <=> 2, ' ', 2 <=> 2, ' ', 3 <=> 2; // -1 0 1