PHP - If/Else... 语句 - 语法差异
PHP - If/Else... statement - Syntax Differences
PHP 菜鸟在这里。我工作的一家公司有一个 if/else 语句设置如下:
{if product_type != ""} {product_type} {if:else}No Product Type{/if}
我做的其他研究提供了如下格式:
<?php if ($bodyID==='home') { ?>
<h1>I am home!</h1>
<?php } else { ?>
<p>I'm not home!</p>
<?php } ?>
语法差异是否有特定原因,或者这只是以前的开发人员编写的方式?
If-Else 语法允许您将评估绑定到第一个 if 语句。这是伪代码,不是PHP:
If (Johnny > 18){ Johnny is a minor} else if (Johnny < 65) { Johnny is an adult} else {Johnny is eligible for Social Security}
从你问的问题来看,第二个if条件可能嵌套在第一个if-else语句中。
If (x > 0){ do Y}
Else{
If(x < 100){do Z}
Else {do A}
}
第一个不是php,它是一个模板引擎,可能是https://ellislab.com/expressionengine/user-guide/templates/conditionals.html。第二个是有效的 php 代码。
PHP 菜鸟在这里。我工作的一家公司有一个 if/else 语句设置如下:
{if product_type != ""} {product_type} {if:else}No Product Type{/if}
我做的其他研究提供了如下格式:
<?php if ($bodyID==='home') { ?>
<h1>I am home!</h1>
<?php } else { ?>
<p>I'm not home!</p>
<?php } ?>
语法差异是否有特定原因,或者这只是以前的开发人员编写的方式?
If-Else 语法允许您将评估绑定到第一个 if 语句。这是伪代码,不是PHP:
If (Johnny > 18){ Johnny is a minor} else if (Johnny < 65) { Johnny is an adult} else {Johnny is eligible for Social Security}
从你问的问题来看,第二个if条件可能嵌套在第一个if-else语句中。
If (x > 0){ do Y}
Else{
If(x < 100){do Z}
Else {do A}
}
第一个不是php,它是一个模板引擎,可能是https://ellislab.com/expressionengine/user-guide/templates/conditionals.html。第二个是有效的 php 代码。