看板 PHP 關於我們 聯絡資訊
※ 引述《alpe (薛丁格的貓)》之銘言: : ※ 引述《aaronsoso (YA教授)》之銘言: : : 目標: : : 我網頁每五秒會refresh一次 : : 一但發現檔案數目有變動會出現一個警告視窗 : : 我到我現在PO文為止所寫的程式碼為 : : $fd =opendir('.'); : 是我見寡事少,還是... : 我真的沒看過這種寫法說. : while(): !? : while(){ : //dosomething : } 那是方便 HTML 中夾雜 迴圈、判斷的寫法 <? while(true): ?> <div> BLAH BLAH </div> <? endwhile ?> 等同於 <? while(true) { echo "<div> BLAH BLAH </div>" } ?> 除此之外還有 <? if(true): ?> <? else: ?> <? endif ?> <? foreach( $items as $key => $item): ?> <? endforeach ?> ... 等,請參考 http://tw.php.net/manual/en/control-structures.alternative-syntax.php 通常在 php 混著 html 的情況下,如果只是做些簡單的 邏輯判斷、或跑跑迴圈,用這種表示滿簡潔易懂的。 不過若是在純 php code 中,建議還是依習慣用 { } 將邏輯區塊包起來,程式碼會較容易閱讀、不易看錯 :) -- 「640K ought to be enough for anybody.!」 - Bill Gates - -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.119.199.121
alpe:受教了 <(_ _)> 12/14 08:51
foxzgerald::) 12/15 01:22