PHP大数加算

2325 ワード

<?PHP $a = '234567890'; $b = '111111111111101'; $m = strlen($a); $n = strlen($b); $num = $m>$n?$m:$n; $result = ''; $flag = 0; while($num--){ $t1 = 0; $t2 = 0; if($m>0){ $t1 = $a[--$m]; } if($n>0){ $t2 = $b[--$n]; } $t = $t1+$t2+$flag; $flag = $t/10; $result = ($t%10).$result; } echo $result; echo "\r
"
; echo $a+$b; ?>