在PHP中,正常情况下elseif和else if的用法及效果是一样的,但在使用带冒号的if语句时(也就是php替代)情况会有点不一样,比如:
/*正确的写法*/
$a = 1;
$b = 2;
if ($a > $b):
echo 'a is larger than b';
elseif ($a < $b):
echo 'a is smaller than b';
else:
echo 'a is equals b';
endif;
==================
/*错误的写法,解析器会报错*/
$a = 1;
$b = 2;
if ($a > $b):
echo 'a is larger than b';
else if ($a < $b):
echo 'a is smaller than b';
else:
echo 'a is equals b';
endif;
?>
php替代实例
if ($a == 5):
echo "a equals 5";
echo "...";
elseif ($a == 6):
echo "a equals 6";
echo "!!!";
else:
echo "a is neither 5 nor 6";
endif;
?>
微信扫一扫 、关注公众号
不定时分享资料视频