Maison > développement back-end > tutoriel php > PHP大数据加法

PHP大数据加法

WBOY
Libérer: 2016-07-30 13:29:50
original
1287 Les gens l'ont consulté

<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>
Copier après la connexion

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

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

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal