栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/594798.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号