function add($a,$b){
$a = strrev($a);
$b = strrev($b);
$tmp = 0;
$tmp_c = 0;
$count = '';
$len = strlen($a)>strlen($b)?strlen($a):strlen($b);
for($i=0;$i<$len;$i++){
if(isset($a[$i]) && isset($b[$i])){
$tmp_c = $a[$i] + $b[$i] + $tmp;
if($tmp_c > 10) {
$tmp = 1;
$count = substr($tmp_c,1).$count;
} else {
$tmp = 0;
$count = $tmp_c.$count;
}
} elseif(isset($a[$i])) {
$tmp_c = $a[$i] + $tmp;
if($tmp_c > 10) {
$tmp = 1;
$count = substr($tmp_c,1).$count;
} else {
$tmp = 0;
$count = $tmp_c.$count;
}
} elseif(isset($b[$i])) {
$tmp_c = $b[$i] + $tmp;
if($tmp_c > 10) {
$tmp = 1;
$count = substr($tmp_c,1).$count;
} else {
$tmp = 0;
$count = $tmp_c.$count;
}
}
}
return $count;
}
PHP大数据加法
最新推荐文章于 2021-04-13 11:52:00 发布