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 === string $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.0230.04020.19
7.0.10.0030.09320.04
7.0.00.0030.04320.25
5.6.170.0230.04720.51
5.6.160.0070.07320.51
5.6.150.0070.07718.16
5.6.140.0070.06718.18
5.6.130.0030.04318.18
5.6.120.0170.04320.98
5.6.110.0030.09320.99
5.6.100.0070.04021.11
5.6.90.0000.06721.00
5.6.80.0100.07020.41
5.5.310.0230.04320.27
5.5.300.0070.08017.95
5.5.290.0070.05317.98
5.5.280.0070.08720.88
5.5.270.0100.08020.96
5.5.260.0030.07720.79
5.5.250.0070.03720.61
5.5.240.0200.07720.26

preferences:
139.63 ms | 1394 KiB | 7 Q