我最近将我的网站移到了Blue Host,这个功能是循环的一部分:
if ($InvoiceType == '18')
{
echo 'Sum Before addition = ' . $sumInvoice . '<br/>';
$sumInvoice += $complete[$key][5];
print 'Invoice being added = ' . $complete[$key][5] . '<br/>'
. 'Sum after addition = '. $sumInvoice . '<br/>';
}
归来这个:
Sum Before addition = 0
Invoice being added = 15174.20
Sum after addition = 1
Sum Before addition = 1
Invoice being added = 4604.25
Sum after addition = 5
Sum Before addition = 5
Invoice being added = 63810.83
Sum after addition = 11
转储$ complete:
Array
(
[0] => Array
(
[0] => 2161
[1] => 638697
[2] => CLIV0286
[3] => Central Medical Supply Inc.
[4] => 0.00
[5] => 15174.20
[6] => 04/01/2011
[7] => 2/1-2/28/11 Fairlawn
[8] => PM2
[9] => 18
)
[1] => Array
(
[0] => 2161
[1] => 638698
[2] => CLIV0286
[3] => Central Medical Supply Inc.
[4] => 0.00
[5] => 4604.25
[6] => 04/01/2011
[7] => 2/1-2/28/11 Atrium
[8] => PM2
[9] => 18
)
[2] => Array
(
[0] => 2161
[1] => 638699
[2] => CLIV0286
[3] => Central Medical Supply Inc.
[4] => 0.00
[5] => 63810.83
[6] => 04/01/2011
[7] => 2/1-2/28/11 Parsippany
[8] => PM2
[9] => 18
)
)
我做错了什么?
答案 0 :(得分:1)
所以这不起作用?
$sumInvoice = 0;
//Init Loop
if ($InvoiceType == '18')
{
echo 'Sum Before addition = ' . $sumInvoice . '<br/>';
$sumInvoice = 0 + floatval(trim($complete[$key][5])) + floatval($sumInvoice);
print 'Invoice being added = ' . $complete[$key][5] . '<br/>'
. 'Sum after addition = '. $sumInvoice . '<br/>';
}
尝试这种小规模测试:
$val = "10.25";
echo (floatval($val) + 10);
答案 1 :(得分:0)
$sumInvoice += (float)$complete[$key][5];
或
$sumInvoice += floatval( $complete[$key][5] );