I don't know it's what you need or not.
function calculate($array_1, $array_2){
$x = 0; $total = 0;
foreach($array_1 as $element){
$total += ($element - $array_2[$x]);
$x++;
}
return ($total / count($array_1));
}
echo calculate(array(6, 3, 3, 4), array(8, 7, 6, 5));
Check this link too see how code run. Hope this helps