<?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);
You have javascript disabled. You will not be able to edit any code.