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.
2 Answers
+ 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>';
}
?>
0
thank you @sadegh