php - How do i multiply values of an array -
i error message "array_product() expects parameter 1 array, string given in..." when try multiply values in foreach statement below. kindly help. in advance
here code. note values in $answer "1.50 real(yes)". need "1.50" many in loop multiply , total.
foreach($_post['gm'] $key => $answer){ if($answer != ''){ $odd=explode(" ",$answer); $od=trim($odd[0]); } $total = array_product($od); echo $total;
i try multiplication outside loop above $total. not repeat in loop. please?
you not reconstructing array in foreach loop. $od
variable overridden each time loop.
your code should be
foreach($_post['gm'] $key => $answer) { if($answer != '') { $odd = explode(" ",$answer); $od[] = trim($odd[0]); } } $total = array_product($od); echo $total;
Comments
Post a Comment