用PHP if/else解释条件html/javascript/css/其他语言代码


Explain conditional html / javascript / css / other language code with PHP if/else

我知道下面的控制流是有效的。我的问题更具概念性:第2行或第4行如何在PHP if/else中作为HTML运行,而不需要任何echos或其他PHP语法?如果条件为false,PHP如何在以后的其他操作中恢复?我想我只是对代码的意义和它的实际工作方式感到困惑。

1  <?php if (condition): ?>
2  //html code to run if condition is true
3  <?php else: ?>
4  //html code to run if condition is false
5  <?php endif ?>

当php被逐行处理并且遇到IF条件时,如果条件为true,则处理继续到下一行。否则,过程将查找end of IF或ELSE IF等的结束

任何不在中间的东西都会按原样输出。但在HTML位于两个PHP块中间的情况下,如果有任何条件语句,则HTML在条件之间的条件只会根据条件的结果输出。

更多详细信息,请访问http://www.onlamp.com/pub/a/php/2001/05/03/php_foundations.html