@ 2015-11-27T16:30:41Z <?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);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
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).
Version System time (s) User time (s) Memory (MiB) 7.2.0 0.004 0.007 19.51 7.1.10 0.000 0.010 18.14 7.1.7 0.000 0.008 17.19 7.1.6 0.010 0.007 19.50 7.1.5 0.009 0.009 16.70 7.1.0 0.003 0.077 22.35 7.0.20 0.003 0.006 16.61 7.0.6 0.003 0.070 20.05 7.0.5 0.000 0.043 17.75 7.0.4 0.000 0.047 20.04 7.0.3 0.037 0.070 20.20 7.0.2 0.023 0.083 20.06 7.0.1 0.003 0.060 20.33 7.0.0 0.007 0.090 20.25 5.6.28 0.003 0.073 21.06 5.6.21 0.017 0.053 20.56 5.6.20 0.007 0.083 18.19 5.6.19 0.003 0.090 20.67 5.6.18 0.043 0.057 20.47 5.6.17 0.027 0.050 20.47 5.6.16 0.000 0.043 20.46 5.6.15 0.007 0.063 18.33 5.6.14 0.007 0.080 18.18 5.6.13 0.007 0.083 18.10 5.6.12 0.000 0.047 21.11 5.6.11 0.010 0.050 21.00 5.6.10 0.000 0.050 20.99 5.6.9 0.013 0.050 20.98 5.6.8 0.000 0.043 20.42 5.5.35 0.003 0.063 20.46 5.5.34 0.003 0.067 18.08 5.5.33 0.003 0.053 20.18 5.5.32 0.013 0.053 20.24 5.5.31 0.030 0.030 20.34 5.5.30 0.007 0.057 18.00 5.5.29 0.000 0.043 17.95 5.5.28 0.010 0.080 20.76 5.5.27 0.010 0.060 20.78 5.5.26 0.003 0.043 20.82 5.5.25 0.013 0.073 20.63 5.5.24 0.020 0.067 20.21
preferences:dark mode live preview
34.44 ms | 401 KiB | 5 Q