时间:2021-07-01 10:21:17 帮助过:16人阅读
废话不多说了,具体代码如下所示:
function getIntAdd($a,$b){ $c = ''; $bCount = strlen($b); $aCount = strlen($a); $count = max($bCount,$aCount); $aDiff = $count - $aCount; $bDiff = $count - $bCount; for($i = $count - 1;$i >= 0;$i--){ $aVal = $count - $i <= $aCount ? intval($a[$i - $aDiff]) : 0; $bVal = $count - $i <= $bCount ? intval($b[$i - $bDiff]) : 0; $v = $aVal + $bVal; if(strlen($c) > 0 && strlen($c) >= $count - $i){ $c = ($v + intval($c[0])).substr($c,1,strlen($c) - 1); }else{ $c = $v.$c.''; } } return $c; } $a = '23490234328490289048902384908392849238'; $b = '234320498324982390489328498230984982399290384902384'; $c = getIntAdd($a,$b); print_r($c);
相关推荐:
PHP计算时间差
PHP计算余弦相似度算法实例
以上就是PHP计算两个特别大的整数实例代码的详细内容,更多请关注Gxl网其它相关文章!