0

我最近将我的网站移至 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
    )
)

我究竟做错了什么?

4

2 回答 2

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);
于 2011-04-14T02:38:49.370 回答
0
$sumInvoice += (float)$complete[$key][5];

或者

$sumInvoice += floatval( $complete[$key][5] );

浮点数()

于 2011-04-14T02:26:44.977 回答