coklat12 Posted November 9, 2007 Share Posted November 9, 2007 hello. i have two arrays : $quantity = array(1,2,3); $price = array(15.45,12.3,23); how do i make those two arrays for a multiply calculation like this : $total = $quantity * $price; i want the total of the calculations in a new array please help me thanks. Link to comment https://forums.phpfreaks.com/topic/76631-solved-simple-calculation-between-array/ Share on other sites More sharing options...
coklat12 Posted November 9, 2007 Author Share Posted November 9, 2007 anybody pls help me. how to solve this Link to comment https://forums.phpfreaks.com/topic/76631-solved-simple-calculation-between-array/#findComment-388025 Share on other sites More sharing options...
GingerRobot Posted November 9, 2007 Share Posted November 9, 2007 Try: <?php $quantity = array(1,2,3); $price = array(15.45,12.3,23); $totals = array(); for($x=0;$x<count($quantity);$x++){ $totals[] = $quantity[$x]*$price[$x]; } echo '<pre>'; print_r($totals); echo '</pre>'; ?> Link to comment https://forums.phpfreaks.com/topic/76631-solved-simple-calculation-between-array/#findComment-388028 Share on other sites More sharing options...
coklat12 Posted November 9, 2007 Author Share Posted November 9, 2007 it works! thanks! Link to comment https://forums.phpfreaks.com/topic/76631-solved-simple-calculation-between-array/#findComment-388055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.