I get an error when trying to rebuild an array with below code:
PHP Fatal error: Uncaught Error: Unsupported operand types
$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);
Other answers suggest that I am trying to do some arithmetic on an array however I cannot see this in the above code.
+
in PHP. I'll write up an answer.