Our Scripts Vault contains many game scripts that you can use to create your own game!
$array1 = json_decode('{"str":"10","dex":"7","vit":"8","dmg":"12","def":"8","mag":"3"}', true); $array2 = json_decode('{"str":"5","dex":"1","vit":"10","dmg":"5","def":"2"}', true); function sum($array1,$array2){$tmp = array();foreach($array1 as $k=>$v) $tmp[$k] = $v + $array2[$k];return($tmp);} print_r(sum($array1, $array2));
function sum($array1,$array2) { $tmp = $array1; foreach($array2 as $k=>$v) $tmp[$k] += $array2[$k]; return($tmp);}
function my_array_sum (array $a, array $b){ $tmp = call_user_func_array ('array_merge_recursive', func_get_args ()); foreach ($tmp as $k => $v) { $tmp [$k] = (is_array ($v)) ? array_sum ($v) : int_val ($v); } return $tmp;}
function my_array_sum (array $a, array $b){ $args = func_get_args (); $tmp = call_user_func_array ('array_merge_recursive', $args); foreach ($tmp as $k => $v) { $tmp [$k] = (is_array ($v)) ? array_sum ($v) : intval ($v); } return $tmp;}// Do the test.$array1 = json_decode('{"str":"10","dex":"7","vit":"8","dmg":"12","def":"8","mag":"3"}', true);$array2 = json_decode('{"str":"5","dex":"1","vit":"10","dmg":"5","def":"2"}', true);echo '<pre>';print_r ($array1);print_r ($array2);print_r(my_array_sum($array1, $array2));echo '</pre>';
wouldnt it be less difficult if you just added "mag":"0" to the second array?