2012-07-16 124 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.

结肠是简单地句法,并且是类似于花括号{}的功能。