0

How to multiply array items?

$array1=array(2,4,6,8,10); $array2=array(3,6,9,12,15); I want to multiply each item of array1 to array2 and print it on the screen.

16th Dec 2016, 3:51 PM
dash8
dash8 - avatar
2 Antworten
+ 3
U can Use this code: <?php $arr1 = array(2,4,6,8,10); $arr2 = array(3,6,9,12,15); // if the length of the two arrays are not the same if (count($arr1) <= count($arr2)) { $length = count($arr1); } else { $length = count($arr2); } // multiply the items together for ($i=0; $i < $length; $i++) { echo $arr1[$i] * $arr2[$i] .'<br>'; } ?>
16th Dec 2016, 4:03 PM
Sadegh Shaikhi
Sadegh Shaikhi - avatar
0
thank you @sadegh
18th Dec 2016, 5:14 AM
dash8
dash8 - avatar