3

I've been reading some joomla code today and I'm often encountering statements like the following:

<?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; ?> 

The way I read it, it seems to translate to the following syntax:

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

I'm not familiar with this syntax (: after the if statement). Can anyone point me to the right place?

4

2 回答 2

5

Check this Alternative syntax for control structures:

PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.

于 2012-07-16T15:15:54.793 回答
3

See PHP documentation:

Reference: 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.

The colon is simply syntactic, and is similar to the functionality of curly braces {}.

于 2012-07-16T15:15:05.993 回答