首页 > 后端开发 > php教程 > PHP大数据加法

PHP大数据加法

WBOY
发布: 2016-07-30 13:29:50
原创
1287 人浏览过

<code><span><span>function</span><span>add</span><span>(<span>$a</span>,<span>$b</span>)</span>{</span><span>$a</span> = strrev(<span>$a</span>);
    <span>$b</span> = strrev(<span>$b</span>);
    <span>$tmp</span> = <span>0</span>;
    <span>$tmp_c</span> = <span>0</span>;
    <span>$count</span> = <span>''</span>;
    <span>$len</span> = strlen(<span>$a</span>)>strlen(<span>$b</span>)?strlen(<span>$a</span>):strlen(<span>$b</span>);
    <span>for</span>(<span>$i</span>=<span>0</span>;<span>$i</span>$len;<span>$i</span>++){
        <span>if</span>(<span>isset</span>(<span>$a</span>[<span>$i</span>]) && <span>isset</span>(<span>$b</span>[<span>$i</span>])){
            <span>$tmp_c</span> = <span>$a</span>[<span>$i</span>] + <span>$b</span>[<span>$i</span>] + <span>$tmp</span>;
            <span>if</span>(<span>$tmp_c</span> > <span>10</span>) {
                <span>$tmp</span> = <span>1</span>;
                <span>$count</span> = substr(<span>$tmp_c</span>,<span>1</span>).<span>$count</span>;
            } <span>else</span> {           
                <span>$tmp</span> = <span>0</span>;      
                <span>$count</span> = <span>$tmp_c</span>.<span>$count</span>;
            }           
        } <span>elseif</span>(<span>isset</span>(<span>$a</span>[<span>$i</span>])) {
            <span>$tmp_c</span> = <span>$a</span>[<span>$i</span>] + <span>$tmp</span>;
            <span>if</span>(<span>$tmp_c</span> > <span>10</span>) {
                <span>$tmp</span> = <span>1</span>; 
                <span>$count</span> = substr(<span>$tmp_c</span>,<span>1</span>).<span>$count</span>;
            } <span>else</span> {      
                <span>$tmp</span> = <span>0</span>; 
                <span>$count</span> = <span>$tmp_c</span>.<span>$count</span>;
            }             
        } <span>elseif</span>(<span>isset</span>(<span>$b</span>[<span>$i</span>])) {
            <span>$tmp_c</span> = <span>$b</span>[<span>$i</span>] + <span>$tmp</span>;
            <span>if</span>(<span>$tmp_c</span> > <span>10</span>) {
                <span>$tmp</span> = <span>1</span>; 
                <span>$count</span> = substr(<span>$tmp_c</span>,<span>1</span>).<span>$count</span>;
            } <span>else</span> {      
                <span>$tmp</span> = <span>0</span>; 
                <span>$count</span> = <span>$tmp_c</span>.<span>$count</span>;
            }             
        }                 
    }                     
    <span>return</span><span>$count</span>;        
}</code>
登录后复制

版权声明:转载请保留文章署名和链接

以上就介绍了PHP大数据加法,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板