I have a simple problem, but I can't solve it, still.
Working code
(int)$sum_price=4;
(int)$price_per_sum = (int)$spo[$key]*(int)$gpp['price'];
echo $sum_price = ($sum_price + $price_per_sum);
When I change 4
to a variable, the result of sum()
is string.
Result becomes a string
$spo[$key] = 1;
$gpp['price'] = 2;
(int)$sum_price=4;
(int)$price_per_sum = (int)$spo[$key]*(int)$gpp['price'];
echo $sum_price = ($sum_price + $price_per_sum);
The result is 42 but should be 6, instead. Using (int)
does not change my result.
Problem code
# Get All Payment
(int)$sum_price = 0;
$sum_price_product = explode('|',$_SESSION['product']);
$spo = explode('|',$_SESSION['order']);
foreach($sum_price_product as $key=>$spp)
{
if($spp!='')
{
$get_product_price = $dbc->select("sh_product"," id = '{$spp}'","id");
$gpp = mysql_fetch_array($get_product_price['sql']);
(int)$price_per_sum = $spo[$key] * $gpp['price'];
$sum_price = $sum_price + $price_per_sum;
echo $sum_price;
}
}