3v4l.org

run code in 300+ PHP versions simultaneously
<?php // groupA: // James: // gpa: 3 // age: 13 // Charles: // gpa: 4 // age: 15 // John: // gpa: 2 // age: 17 $groupA = [ 'James' => [ 'gpa' => 3, 'age' => 13 ], 'Charles' => [ 'gpa' => 4, 'age' => 15 ], 'John' => [ 'gpa' => 2, 'age' => 17 ] ]; /** * @throws \InvalidArgumentException */ function getPlace(string $for, string $compareValueKey, array $haystack, int $flags = SORT_REGULAR): int { if(empty($haystack) || !isset($haystack[$for])) { throw new \InvalidArgumentException("empty haystack array given (or key '$for') was not found"); } $sort = array_map(fn(array $el) => $el[$compareValueKey], $haystack); arsort($sort, $flags); $place = array_search($for, $places = array_keys($sort), true); if(!is_int($place)) { throw new \RuntimeException("could not locate position for key '$for' in given array: " . trim(implode(', ', $places))); } return $place + 1; } $persons = array_keys($groupA); foreach($persons as $person) { echo $person . ': ' . getPlace($person, 'age', $groupA) . PHP_EOL; }

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.3.70.0140.00316.63
8.3.60.0070.01116.50
8.3.50.0070.01016.30
8.3.40.0080.00818.89
8.3.30.0100.01019.02
8.3.20.0050.00324.18
8.3.10.0040.00424.66
8.3.00.0050.00326.16
8.2.190.0080.00818.41
8.2.180.0110.01125.92
8.2.170.0060.00919.04
8.2.160.0120.00922.96
8.2.150.0000.00725.66
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0120.00326.16
8.2.110.0060.00320.12
8.2.100.0000.00919.23
8.1.280.0100.01025.92
8.1.270.0040.00423.99
8.1.260.0000.00726.35
8.1.250.0000.00828.09
8.1.240.0000.01118.47
8.1.230.0060.00322.14
8.0.90.0020.00616.88

preferences:
28.24 ms | 401 KiB | 5 Q