3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $selector = 'foo[bar][foo]'; $input = array('foo' => array('bar' => array('foo' => 'poop'))); $value = $input; $path = explode('[', str_replace(']', '', $selector)); foreach ($this->selector_path as $name) { if (array_key_exists($name, $value)) { $value = $value[$name]; } else { $value = null; break; } } var_dump($value);
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Using $this when not in object context in /in/Nsvvc:10 Stack trace: #0 {main} thrown in /in/Nsvvc on line 10
Process exited with code 255.
Output for hhvm-3.12.0
Fatal error: Uncaught Error: $this is null in /in/Nsvvc:10 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.10.0
Fatal error: $this is null in /in/Nsvvc on line 10
Process exited with code 255.
Output for 5.0.0 - 5.6.28
Fatal error: Using $this when not in object context in /in/Nsvvc on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.10, 4.4.0 - 4.4.9
Warning: Invalid argument supplied for foreach() in /in/Nsvvc on line 10 array(1) { ["foo"]=> array(1) { ["bar"]=> array(1) { ["foo"]=> string(4) "poop" } } }
Output for 4.3.11
array(1) { ["foo"]=> array(1) { ["bar"]=> array(1) { ["foo"]=> string(4) "poop" } } }