3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); /** * Write a function that accepts an array of strings and return another array * with strings in the input array set as keys. * * @param string[] $arrOfStrings An array of strings. * @return array Another array with strings in the input array set as keys. */ function foo(array $arrOfStrings): array { return array_fill_keys(array_filter($arrOfStrings, 'is_string'), null); } /** * Now write another function that accepts the output of the previous function, * as first argument and another string as second argument. In this function, * assume that you have some reason to iterate over the the input array using * foreach, key => value format. In every iteration, in addition to other stuff, * you also have to check if the key is equal to the input string (the second * parameter of this function), and if they match do some stuff.... * * @param array $outputFromFoo The output from {@link foo()}. */ function bar(array $outputFromFoo, string $str) { foreach ($outputFromFoo as $key => $value) { // other stuff print "$key\n"; if (string $key === $str) { echo "Found $str!"; } } } $result = foo(array('ab', 'cd', '10')); bar($result, '10');

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)
7.0.20.0200.05720.23
7.0.10.0070.06320.19
7.0.00.0030.04320.07
5.6.170.0270.05020.71
5.6.160.0070.04320.50
5.6.150.0130.07018.19
5.6.140.0070.08318.25
5.6.130.0100.03718.27
5.6.120.0100.08021.02
5.6.110.0130.08020.89
5.6.100.0000.04321.12
5.6.90.0070.08320.97
5.6.80.0030.07320.41
5.5.310.0230.08020.28
5.5.300.0000.05717.96
5.5.290.0100.08317.98
5.5.280.0230.07320.65
5.5.270.0100.07320.88
5.5.260.0000.08720.77
5.5.250.0030.04020.61
5.5.240.0270.07320.16

preferences:
145.28 ms | 1394 KiB | 7 Q