PHP条件语句,是否需要括号?

PHP条件语句,是否需要括号?,第1张

PHP条件语句,是否需要括号

您可以执行以下其他语句:

<?phpif ($something) {   echo 'one conditional line of pre';   echo 'another conditional line of pre';}if ($something) echo 'one conditional line of pre';if ($something)echo 'one conditional line of pre';echo 'a NON-conditional line of pre'; // this line gets executed regardless of the value of $something?>

然后您还可以编写if-else的替代语法

<?phpif ($something):   echo 'one conditional line of pre';   echo 'another conditional line of pre';elseif ($somethingElse):   echo 'one conditional line of pre';   echo 'another conditional line of pre';else:   echo 'one conditional line of pre';   echo 'another conditional line of pre';endif;?>

使用备用语法,您也可以退出解析模式,如下所示:

<?phpif ($something):?>one conditional line of pre<br />another conditional line of pre<?phpelse:   echo "it's value was: $value<br />n";?>another conditional line of pre<?phpendif;?>

但这真的很快就会变得凌乱,我不建议您使用它(除非用于模板逻辑)。

并使其完整:

<?php$result = $something ? 'something was true' : 'something was false';echo $result;?>equals<?phpif ($something) {   $result = 'something was true';} else {   $result = 'something was false';}echo $result;?>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5585989.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存