看板 PHP 關於我們 聯絡資訊
PHP uses semicolons to separate simple statements. A compound statement that uses curly braces to mark a block of code, such as a conditional test or loop, does not need a semicolon after a closing brace. Unlike in other languages, in PHP the semicolon before the closing brace is not optional: 各位板友好,近期剛接觸PHP,最近在讀的書裡面提到分號的使用,有些不明之處, 故節錄部分原文,希望板友能不吝指點 前兩句其實跟C語言是一樣的使用原則,我可以理解它的意思。 但是最後一句,如果我沒解讀錯誤的話,它是說PHP跟其他語言的差異,在於結束括號 的前面一定要加分號。 例: if ($needed) { echo "xxx"; } 如上例,確實是有在結束括號前加分號,但作者為什麼會寫說這是跟其他語言的差異呢? 因為像C語言應該也是這樣子的,感覺這不是什麼特殊的屬性。 還請板友多多指教,謝謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.248.71.184
Jerr:因為的確有其他語言不用加分號啊 09/11 11:19
danny8376:對PHP而言的對照組語言不會是C那種啦XD 09/11 11:57
edash:謝謝回應 09/11 17:01
chrisQQ:python 表示 09/12 13:54