2012-07-16 126 views
3

我一直在閱讀一些joomla代碼今天我經常遇到類似的語句如下:這個if語句的含義[if(condition):something; ENDIF]

<?php if (intval($this->item->modified) != 0 && $this->item->params->get('show_modify_date')) : ?> 
      <tr> 
       <td colspan="2" class="modifydate"><?php echo JText::sprintf('LAST_UPDATED2', JHTML::_('date', $this->item->modified, JText::_('DATE_FORMAT_LC2'))); ?> </td> 
      </tr> 
<?php endif; ?> 

我讀的方式,似乎翻譯爲語法如下:

if (condition) : 
    // do something here 
endif; 

我不熟悉這個語法(:if聲明後面)。任何人都可以將我指向正確的地方嗎?

+0

可能重複[在PHP中是什麼類型的語法?](http://stackoverflow.com/questions/2081442/what-kind-of-syntax-is-this-in-php) – nickb 2012-07-16 15:19:52

+0

@ Jeroen谷歌,地獄呀!但請不要妄下結論。這種(奇怪的語法)很容易被忽略,除非人們閱讀手冊封面來覆蓋或在現有代碼中遇到此聲明(就像我今天所做的那樣)。嘗試谷歌搜索'如果php:'看看是否拋出相關的結果。你能給我一些關鍵詞來搜索,以便我得到所需的結果嗎? – 2012-07-16 15:22:37

+0

我的評論已被刪除,但它是一個鏈接到'php endif'的谷歌結果頁面,第一個結果肯定是你需要的。 – Jeroen 2012-07-16 15:49:15

回答

5

入住此Alternative syntax for control structures

PHP提供了一種替代語法一些控制結構; 即,if,while,for,foreach和switch。在每種情況下,備用語法的基本 形式都是分別將大括號分別更改爲冒號 (:),並將大括號分別改爲endif,endwhile,endfor ;, endforeach, 或endswitch。

+0

爲您提供直接鏈接。 – 2012-07-16 16:22:29

3

參見PHP文檔:

參考http://php.net/manual/en/control-structures.elseif.php

Note: Note that elseif and else if will only be considered exactly the same when using curly brackets as in the above example. When using a colon to define your if/elseif conditions, you must not separate else if into two words, or PHP will fail with a parse error.

結腸是簡單地句法,並且是類似於花括號{}的功能。