There is a function that adds the elements of array_sum.
And I want to do that, which subtracts the elements of the array and I can not.
$arr2 = array(1,2,3,4); function foo2($mass, $znak){ $res = $mass[0]; foreach($mass as $value){ echo $res = $res - $value; }; return $res; }; foo2($arr2); If I write 0 to the $ res variable, then immediately it will be subtracted from zero, and I need, first, to subtract 2 from 1.
How to do it?
It should be 1-2-3-4 = -8
And how to do that in a function, you could pass a parameter that decides what to do with the elements? minus plus