首頁  >  文章  >  後端開發  >  PHP大數據加法

PHP大數據加法

WBOY
WBOY原創
2016-07-30 13:29:501279瀏覽

<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>

版權聲明:轉載請保留文章署名和連結

以上就介紹了PHP大數據加法,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn