简体   繁体   中英

Adding in PHP returns string addition. 10+12=1012!!!! I need 10+12=22

My Code :

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

There are two values in db viz 10 and 12.my answer is coming as 01012. My answer should be 22...Help pls

It should be like this:

$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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM