PHP大数据加法

来源:互联网 发布:阿里云ecs 微信公众号 编辑:程序博客网 时间:2024/05/16 05:24
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;        }
0 0