2,"Spade"=>5,"Drill"=>2]; ksort($stock); foreach ($stock as $name=>$count) echo "$name: $count\n"; $rows = [["id"=>3,"count"=>2],["id"=>1,"count"=>2]]; usort($rows, fn(array $a,array $b): int => ($a["count"] <=> $b["count"]) ?: ($a["id"] <=> $b["id"])); echo "First id: ", $rows[0]["id"], "\n";