Home  >  Article  >  Backend Development  >  PHP big data addition

PHP big data addition

WBOY
WBOYOriginal
2016-07-30 13:29:501278browse

<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><<span>$len</span>;<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>

Copyright Statement: Please keep the article signature and link when reprinting

The above introduces PHP big data addition, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn