3v4l.org

run code in 300+ PHP versions simultaneously
<?php $menu = [ (object)[ 'tid' => 24, 'name' => 'Sample', 'weight' => 3, 'depth' => 0 ], (object)[ 'tid' => 66, 'name' => 'Sample Subcategory', 'weight' => 0, 'depth' => 1 ], (object)[ 'tid' => 67, 'name' => 'Another Example', 'weight' => 1, 'depth' => 0 ], (object)[ 'tid' => 68, 'name' => 'Subcategory for Another Example', 'weight' => 1, 'depth' => 1 ], (object)[ 'tid' => 22, 'name' => 'A third example master category', 'weight' => 0, 'depth' => 0 ] ]; usort($menu, function($a, $b) { return [$a->depth, $a->weight] <=> [$b->depth, $b->weight]; }); var_export($menu);

preferences:
35.89 ms | 405 KiB | 5 Q