3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $id = '9242'; $supergroup = array('9242' => 1, '9243' => 0, '9244' => 2, '9245' => 0); $supergroupnew = []; array_walk_recursive($supergroup, function($item, $key) use(&$id) { if ($key == $id) { $supergroupnew += [ $key => $item ]; } else { $supergroupnew += [ $key => "0" ]; } }); echo "<h1>Original Array:</h1>"; print_r($supergroup); echo "<h1>New Array:</h1>"; print_r($supergroupnew);
based on hYpSB
Output for 7.0.30 - 7.3.0rc2
Notice: Undefined variable: supergroupnew in /in/J8Nmg on line 8 Fatal error: Uncaught Error: Unsupported operand types in /in/J8Nmg:8 Stack trace: #0 [internal function]: {closure}(1, 9242) #1 /in/J8Nmg(12): array_walk_recursive(Array, Object(Closure)) #2 {main} thrown in /in/J8Nmg on line 8
Process exited with code 255.
Output for hhvm-3.22.0
Fatal error: Invalid operand type was used: cannot perform this operation with arrays in /in/J8Nmg on line -1
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Fatal error: Invalid operand type was used: cannot perform this operation with arrays in /in/J8Nmg on line 8
Process exited with code 255.
Output for 5.6.30
Notice: Undefined variable: supergroupnew in /in/J8Nmg on line 8 Fatal error: Unsupported operand types in /in/J8Nmg on line 8
Process exited with code 255.