3

joomla今日、いくつかのコードを読んでいて、次のようなステートメントによく遭遇します。

<?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誰かが私を正しい場所に向けることができますか?

4

2 に答える 2

5

制御構造のこの代替構文を確認してください。

PHP は、その制御構造の一部に対して代替構文を提供しています。つまり、if、while、for、foreach、および switch です。いずれの場合も、代替構文の基本的な形式は、左中括弧をコロン (:) に、右中括弧をそれぞれ endif;、endwhile;、endfor;、endforeach;、または endwitch; に変更することです。

于 2012-07-16T15:15:54.793 に答える
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.

コロンは単なる構文であり、中括弧の機能に似ています{}

于 2012-07-16T15:15:05.993 に答える