<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 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.