3v4l.org

run code in 300+ PHP versions simultaneously
<?php $orderList = [ 'Jake', 'Scully' => [ 'pet', 'friend' => [ 'Michael', 'Merissa', ], 'Norm', ], 'Amy', 'Charles', 'Hitchcock', ]; $items = [ [ 'name' => 'Scully', ], [ 'name' => 'Rosa', ], [ 'name' => 'Bill', ], [ 'name' => 'Jake', ], [ 'name' => 'Hitchcock', ], [ 'name' => 'Amy', ], ]; function getTopLevelItemsFromMixedList(array $mixedList): array { $topLevels = []; foreach ($mixedList as $item => $value) { $topLevels[] = is_int($item) ? $value : $item; } return $topLevels; } function getComparator(array $order): callable { return function ($a, $b) use ($order) { $indexOfA = array_search($a['name'], $order); $indexOfB = array_search($b['name'], $order); // If both are in the $order list, compare them based on their position in the list if ($indexOfA !== false && $indexOfB !== false) { return $indexOfA <=> $indexOfB; } // If only A is in the $order list, then it must come before B. if ($indexOfA !== false) { return -1; } // If only B is in the $order list, then it must come before A. if ($indexOfB !== false) { return 1; } // If neither is present, fall back to natural sort return strnatcmp($a['name'], $b['name']); }; } $topLevelOrder = getTopLevelItemsFromMixedList($orderList); usort($items, getComparator($topLevelOrder)); print_r($items);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.30.0150.00619.00
8.4.20.0170.00319.40
8.4.10.0060.00322.22
8.3.160.0120.00620.91
8.3.150.0000.00820.66
8.3.140.0040.00418.35
8.3.130.0030.00618.48
8.3.120.0000.01520.53
8.3.110.0030.00620.94
8.3.100.0090.00024.06
8.3.90.0040.00426.77
8.3.80.0090.00016.63
8.3.70.0000.01518.55
8.3.60.0170.00316.50
8.3.50.0110.00418.37
8.3.40.0070.01420.11
8.3.30.0130.00318.66
8.3.20.0000.00824.18
8.3.10.0110.00024.66
8.3.00.0050.00326.16
8.2.270.0140.00417.41
8.2.260.0050.00316.66
8.2.250.0050.00318.34
8.2.240.0060.00318.82
8.2.230.0060.00322.58
8.2.220.0030.01237.54
8.2.210.0040.00426.77
8.2.200.0090.00016.63
8.2.190.0120.00316.63
8.2.180.0040.01125.92
8.2.170.0130.00318.96
8.2.160.0070.01022.96
8.2.150.0040.00425.66
8.2.140.0050.00324.66
8.2.130.0070.00026.16
8.2.120.0070.00021.11
8.2.110.0030.00720.45
8.2.100.0090.00020.47
8.1.310.0080.00017.79
8.1.300.0030.00620.25
8.1.290.0120.00030.84
8.1.280.0040.01425.92
8.1.270.0070.00324.66
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0030.00718.55
8.1.230.0040.00418.76
8.1.100.0050.00217.46

preferences:
25.86 ms | 403 KiB | 5 Q