PHP elseif/else if

elseif 与 else if 只有在条件后使用花括号的情况下才认为是完全相同。

如果用冒号来定义 if/elseif 条件,那就不能用两个单词的 else if,否则 PHP 会产生解析错误。

/* 不正确的使用方法: */
if($a > $b):
    echo $a." is greater than ".$b;
else if($a == $b): // 将无法编译
    echo "The above line causes a parse error.";
endif;
/* 正确的使用方法: */
if($a > $b):
    echo $a." is greater than ".$b;
elseif($a == $b): // 注意使用了一个单词的 elseif
    echo $a." equals ".$b;
else:
    echo $a." is neither greater than or equal to ".$b;
endif;

 所以PHP 的代码里面推荐使用 elseif  连写

但我公司前后端不分离,js 里面else if 是分开写的,为了统一,使用的是else  if 写法

http://www.php.net/manual/zh/control-structures.elseif.php

猜你喜欢

转载自blog.csdn.net/bianb123/article/details/85000127
今日推荐