簡單的PHP演算法題(待完善…)
只印0
具體個數由輸入的參數n決定
如n=5就列印000000印出一行0101010101010101010101
具體個數由輸入的參數n決定 如test.php?n=3印出010
如test.php?n=3印出010 如test.php?n=3印出010 〜 1 0000 11111 for if 實現
<?<span>php </span><span>for</span> (<span>$i</span> = 0; <span>$i</span> < 10; <span>$i</span>++<span>) { </span><span>for</span> (<span>$j</span> = 0; <span>$j</span> <= <span>$i</span>; <span>$j</span>++<span>) { </span><span>if</span> (<span>$i</span> % 2 == 0<span>) { </span><span>echo</span> '0'<span>; } </span><span>else</span><span> { </span><span>echo</span> '1'<span>; } } </span><span>echo</span> '<br/>'<span>; } </span>?>for&if語句實作
<?<span>php </span><span>$i</span> = 0<span>; </span><span>while</span> (<span>$i</span> < 10<span>) { </span><span>$j</span> = 0<span>; </span><span>while</span> (<span>$j</span> <= <span>$i</span><span>) { </span><span>switch</span> (<span>$i</span> % 2<span>) { </span><span>case</span> 0: <span>echo</span> '0'<span>; </span><span>break</span><span>; </span><span>case</span> 1: <span>echo</span> '1'<span>; </span><span>break</span><span>; } </span><span>$j</span>++<span>; } </span><span>echo</span> '<br/>'<span>; </span><span>$i</span>++<span>; } </span>?>while&switch語句實作
實作0 01 010 0101…
實作0 01 012 0123 3210 210 10 0
做個計算器
如test.php?a=6&b=3&operator=chu輸出2
可處理加減乘對 水仙花數 冒泡排序法以上就介紹了簡單的PHP演算法問題(有擴充),包括了方面的內容,希望對PHP教程有興趣的朋友有幫助。