当前位置:Gxlcms > PHP教程 > PHP大数据加法

PHP大数据加法

时间:2021-07-01 10:21:17 帮助过:22人阅读

functionadd($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大数据加法,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行