I have two array
$a = [500,0,300,0];
$b = [0, 100, 0, 100];
My desire output :
$c = [500,400,700,600];
I have tried by below approach, but not getting desire output.
<?php
function get_c()
{
$amount = 0;
if (func_get_arg(0) > 0) {
$amount = $amount + func_get_arg(0);
} else {
$amount = $amount - func_get_arg(1);
}
return $amount;
}
$a = [500,0,300,0];
$b = [0, 100, 0, 100];
$c = array_map(
'get_c',
$a,
$b
);
print_r($c);
Getting output [500,-100,300,-100]
. I understood my amount value always getting zero in if condition. How can I solve this problem ?