PHP中elseif與else if的區別

來源:互聯網
上載者:User

標籤:else   elseif   if   

在PHP中,正常情況下elseif和else if的用法及效果是一樣的,但在使用帶冒號的if語句時(也就是php替代)情況會有點不一樣,比如:

<?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替代執行個體

<?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;
?>



本文出自 “Linux獄長” 部落格,請務必保留此出處http://sswqzx.blog.51cto.com/2494644/1962241

PHP中elseif與else if的區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.