3v4l.org

run code in 500+ PHP versions simultaneously
<?php function cmp_strict(mixed $a, mixed $b): int { if ($a === $b) return 0; $typeA = gettype($a); $typeB = gettype($b); if ($typeA === $typeB) { return match($typeA){ "string" => strcmp($a, $b), "object" => spl_object_id($a) <=> spl_object_id($b), default => $a <=> $b, }; } else { return $typeA <=> $typeB; } } $data = [ 3, 4, 1, "a", "0", "x", 0, 1, 4, STDIN, STDERR, STDOUT, [3], [[4]], [], (object)['a'=>true], new stdClass ]; usort($data, 'cmp_strict'); var_dump($data);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
array(17) { [0]=> array(0) { } [1]=> array(1) { [0]=> int(3) } [2]=> array(1) { [0]=> array(1) { [0]=> int(4) } } [3]=> int(0) [4]=> int(1) [5]=> int(1) [6]=> int(3) [7]=> int(4) [8]=> int(4) [9]=> object(stdClass)#1 (1) { ["a"]=> bool(true) } [10]=> object(stdClass)#2 (0) { } [11]=> resource(1) of type (stream) [12]=> resource(2) of type (stream) [13]=> resource(3) of type (stream) [14]=> string(1) "0" [15]=> string(1) "a" [16]=> string(1) "x" }

preferences:
32.29 ms | 1153 KiB | 7 Q