CKTIS / PHP
uasort()
Use a comparator on values while keeping each original key.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
uasort(array &$array, callable $callback): trueUse a comparator on values while keeping each original key. Return a negative integer, zero or a positive integer for before, equal or after. PHP 8 retains the input order of ties. Decimal comparator results are cast to int and can create unwanted ties.
Signature
uasort(array &$array, callable $callback): true
Example output
["a","b","c"]
Examples
<?php
$jobs = ["c"=>["p"=>2],"a"=>["p"=>1],"b"=>["p"=>1]];
uasort($jobs, fn($left,$right) => $left["p"] <=> $right["p"]);
echo json_encode(array_keys($jobs));
Result
["a","b","c"]