3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Enter your code here, enjoy! $array = array("1" => "PHP code tester Sandbox Online", "foo" => "bar", 5 , 5 => 89009, "case" => "Random Stuff", "PHP Version" => phpversion() ); /** * Config class * * Simple class to store or get elements from configuration registry */ class Config implements ArrayAccess, IteratorAggregate { /** @var array $data Data configuration array */ private $data = []; /** * Class constructor * @param array $data List of values to add to the configuration registry */ public function __construct(array $data = []) { $ritit = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($data)); $result = array(); foreach ($ritit as $leafValue) { $keys = array(); foreach (range(0, $ritit->getDepth()) as $depth) { $keys[] = $ritit->getSubIterator($depth)->key(); } $result[implode('.', $keys)] = $leafValue; } $this->data = $result; } /** * Retrieves elements from config array * * @param string $key * @return mixed returns a config value * @throws Exception when no $key found */ public function get($key) { if (!isset($this->data[$key])) { throw new \Exception('There is no entry for key: ' . $key); } return $this->data[$key]; } /** * Return true if value is empty for given key * * @param string $key * @return bool */ public function isEmpty($key) { return empty($this->data[$key]); } /** * IteratorAggregate interface required method * * @return \ArrayIterator */ public function getIterator() { return new \ArrayIterator($this->data); } /** * Key to set * * @param mixed $key * @param mixed $value * @throws \Exception */ public function offsetSet($key, $value) { if (!$key) { $this->data[] = $value; } else { $this->data[$key] = $value; } } /** * Key to retrieve * * @param mixed $key * @return string|null */ public function offsetGet($key) { if (isset($this->data[$key])) { return $this->data[$key]; } return null; } /** * Whether a key exists * * @param mixed $key * @return bool */ public function offsetExists($key) { return isset($this->data[$key]); } /** * Key to unset * * @param mixed $key */ public function offsetUnset($key) { unset($this->data[$key]); } } $config = new Config($array); var_dump($config);

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.2.00.0040.00719.51
7.1.100.0000.01018.14
7.1.70.0000.00817.19
7.1.60.0100.00719.50
7.1.50.0090.00916.70
7.1.00.0030.07722.35
7.0.200.0030.00616.61
7.0.60.0030.07020.05
7.0.50.0000.04317.75
7.0.40.0000.04720.04
7.0.30.0370.07020.20
7.0.20.0230.08320.06
7.0.10.0030.06020.33
7.0.00.0070.09020.25
5.6.280.0030.07321.06
5.6.210.0170.05320.56
5.6.200.0070.08318.19
5.6.190.0030.09020.67
5.6.180.0430.05720.47
5.6.170.0270.05020.47
5.6.160.0000.04320.46
5.6.150.0070.06318.33
5.6.140.0070.08018.18
5.6.130.0070.08318.10
5.6.120.0000.04721.11
5.6.110.0100.05021.00
5.6.100.0000.05020.99
5.6.90.0130.05020.98
5.6.80.0000.04320.42
5.5.350.0030.06320.46
5.5.340.0030.06718.08
5.5.330.0030.05320.18
5.5.320.0130.05320.24
5.5.310.0300.03020.34
5.5.300.0070.05718.00
5.5.290.0000.04317.95
5.5.280.0100.08020.76
5.5.270.0100.06020.78
5.5.260.0030.04320.82
5.5.250.0130.07320.63
5.5.240.0200.06720.21

preferences:
34.44 ms | 401 KiB | 5 Q