php中的elseif和else if

以前的时候还没注意到,知道进入公司,看的代码多了点,时常看到elseif的分支,而我自己时常用的是else if,于是就注意到,他们既然都可以用,那么他们的却别在哪儿呢?

通过查询,原来,确实有点小小区别:1.一个能用冒号,另外一个不可以

<?php
/* Incorrect Method: */
if($a > $b):
    echo $a." is greater than ".$b;
else if($a == $b): // Will not compile.
    echo "The above line causes a parse error.";
endif;
/* Correct Method: */
if($a > $b):
    echo $a." is greater than ".$b;
elseif($a == $b): // Note the combination of the words.
    echo $a." equals ".$b;
else:
    echo $a." is neither greater than or equal to ".$b;
endif;
?>

 

posted @ 2015-03-19 14:40  suhanyujie  阅读(2087)  评论(0编辑  收藏  举报