public functionbig_integer_add($num1,$num2){
$str1=strval($num1);
$str2=strval($num2);
$length2=strlen($str1);
$length3=strlen($str2);
$length=$length2>$length3?$length2:$length3;
$result='';
$flag=0;
while($length--){
$m=0;
$n=0;
if($length2>0)
$m=$str1[--$length2];
if($length3>0)
$n=$str2[--$length3];
$tmp=$m+$n+$flag;
$flag=$tmp/10;
$result= ($tmp%10).$result;
}
returndoubleval($result);//或者直接返回字符串
}
$a=9874651230987465123098746512309874651230987465123098746512309874651230987465123098746512309874651230;
$b=9874651230987465123098746512309874651230987465123098746512309874651230987465123098746512309874651230;
dump($this->big_integer_add($a,$b));
echo"
";
dump($a+$b) ;
新闻名称:PHP大数字加法大整数加法
文章出自:
http://cdweb.net/article/psdpod.html