3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function array_multiupdate_from_keys(array &$array, array $keys, $value){ if(!empty($keys)){ $key = array_shift($keys); if(key_exists($key, $array)){ $array[$key] = count($keys) > 0 ? array_multiupdate_from_keys($array[$key], $keys, $value) : $array[$key] = $value; } } } $array = array( 'a' => 'a', 'b' => 'b', 'c' => array( 0 => 0, 1 => 1, 2 => array( 'foo', 'bar' ) ) ); $array = array_multiupdate_from_keys($array, array('c', 1, 0), 'updated'); var_dump($array);
based on bIPKX
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught TypeError: Argument 1 passed to array_multiupdate_from_keys() must be of the type array, integer given, called in /in/JjbUB on line 7 and defined in /in/JjbUB:3 Stack trace: #0 /in/JjbUB(7): array_multiupdate_from_keys(1, Array, 'updated') #1 /in/JjbUB(7): array_multiupdate_from_keys(Array, Array, 'updated') #2 /in/JjbUB(25): array_multiupdate_from_keys(Array, Array, 'updated') #3 {main} thrown in /in/JjbUB on line 3
Process exited with code 255.
Output for 5.4.11 - 5.6.28
Catchable fatal error: Argument 1 passed to array_multiupdate_from_keys() must be of the type array, integer given, called in /in/JjbUB on line 7 and defined in /in/JjbUB on line 3
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Catchable fatal error: Argument 1 passed to array_multiupdate_from_keys() must be an array, integer given, called in /in/JjbUB on line 7 and defined in /in/JjbUB on line 3
Process exited with code 255.