gpt4 book ai didi

php - if 和 else if 在 PHP 中,冒号样式

转载 作者:可可西里 更新时间:2023-10-31 22:12:50 27 4
gpt4 key购买 nike

我喜欢使用的 PHP 的一个功能是冒号风格的 if 语句(我不知道它实际上叫什么。)

<?php if(something):?>
<html stuff>
<?php endif;?>

但我最近尝试对多个案例执行此操作:

<?php if(something):?>
<html stuff>
<?php else if(something):?>
<html stuff>
<?php endif;?>

第三行出现错误(else if):

Unexpected T_IF

是否可以通过这种方式制作 if-else if?

最佳答案

我能够让它工作。

在这种非常特殊的情况下,else if 不是 elseif 的同义词。

elseif 代替 else if 解决了这个问题。

<?php if(something):?>
<html stuff>
<?php elseif(something):?>
<html stuff>
<?php endif;?>

来自 PHP.net :

Note: Note that elseif and else if will only be considered exactly the same when using curly brackets as in the above example. When using a colon to define your if/elseif conditions, you must not separate else if into two words, or PHP will fail with a parse error.

关于php - if 和 else if 在 PHP 中,冒号样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29592979/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com