0

Very basically you suppose I have this arrays:

$a = [1,2,3];
$b = [4,5,6];

and now I want to Multiply the numbers of columns, for example:

1*4
2*5
3*6

and get sum multiply of all calculation, for example:

4+10+18 = 32

I need to get this result, I can't implementing this scenario with array_map or array_reduce, using two foreach return wrong result for me

1 Answer 1

3

Try This..

$total = 0;
for($i = 0; $i < count($a); $i++) {
  $total += $a[$i] * $b[$i];
}

echo $total;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.