您可以执行以下其他语句:
<?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;?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)