Subtracting one array from another

arrays, php

Solution

Try this :

$array1  = array(251, 251, 130);
$array2  = array( 13,  13,  50);
$res     = array();
for($i=0;$i<count($array1);$i++){
   $res[$i] = $array1[$i]-$array2[$i];
}

echo "<pre>";
print_r($res);

Problem

I want to subtract one array from another . for example I have 2 arrays. ``` Array ( [0] => 251 [1] => 251 [2] => 130 ) Array ( [0] => 13 [1] => 13 [2] => 50 ) ``` The resulting array has to be ``` Array ( [0] => 238 [1] => 238 [2] => 80 ) ``` Any sort of help on this is appreciated .

Original source

Related problems