3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function forget(&$array, $keys) { $original =& $array; foreach ((array) $keys as $key) { $parts = explode('.', $key); while (count($parts) > 1) { $part = array_shift($parts); if (isset($array[$part]) && is_array($array[$part])) { $array =& $array[$part]; } } unset($array[array_shift($parts)]); // clean up after each pass $array =& $original; } } $a = ['a' => 0, 'b' => 'd']; forget($a, ['b']); print_r($a);
based on CL0Kq
Output for 5.4.0 - 7.2.0
Array ( [a] => 0 )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/vpeVH on line 28
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/vpeVH on line 28
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/vpeVH on line 28
Process exited with code 255.