1

I want to have that variable $total[$i] giving the result of the following function:

$total[$i] = (array_reduce((array_map(function($x, $y) { return $x * $y; },
                   $corp_resp[$i], $corp_resp_template)),function($carry,$item){return $carry+=$item;},0));

I receive from $corp_resp_templateexample: array(0.4,0.2,0.1) for $corp_resp array(array(sub1(0.2,0.3,0.5) arraysub2(0.2,0.5,0.7)))

$corp_resp_template for that operation is only one. $corp_resp is array with subarrays inside that depends of $carCount in that case $carCount=2 if is 4 will give 4 subarrays, where that values will be interpolated with $corp_resp_template will be only one array the same size of $corp_resp.

Example Operation:

Total 1 =(0.4*0.2+0.2*0.3+0.5*0.1)=0.19 $total[0]

Total 2 =(0.4*0.2+0.2*0.5+0.1*0.7)=0.25 $total[1]

That total values will be inserted in lines of a table.

Thank you.

1 Answers1

1

Everything looks quite working:

$corp_resp_template = [0.4,0.2,0.1];
$corp_resp = [[0.2,0.3,0.5],[0.2,0.5,0.7]];

for($i = 0;$i<count($corp_resp);$i++){

    $total[$i] = (array_reduce(array_map(function($x, $y){
      return $x * $y; 
    },$corp_resp[$i], $corp_resp_template),function($carry,$item){return $carry+=$item;},0));
}

print_r($total);

out:

Array
(
   [0] => 0.19
   [1] => 0.25
)
Redr01d
  • 392
  • 2
  • 12