添加PHP会返回字符串添加。 10 + 12 = 1012 !!!!我需要10 + 12 = 22

时间:2018-02-17 12:36:39

标签: php

我的代码:

$gettotz=0;
while($mycartqry=mysqli_fetch_array($cartqry)){
                    $one=$mycartqry['nos'];
                    $two=$gettotz;
                echo $gettotz.=$myVar+$myVar2;
            }

db viz 10和12中有两个值。我的答案是01012.我的答案应该是22 ...帮助请

1 个答案:

答案 0 :(得分:0)

应该是这样的:

$gettotz=0;
while ($mycartqry=mysqli_fetch_array($cartqry)){
    $one = $mycartqry['nos'];
    $gettotz += $one;
    // what is `$myVar` and `$myVar2` is unclear
    // but if they exists you can also add'em:
    // $gettotz += $one + $myVar + $myVar2;
}
echo $gettotz;