2016-08-12 103 views
0

我想請求PHP代碼if-else/if-elseif-else,這個語句:如果usercode=1我想打開file1.phpPHP IF-ELSEIF-ELSE /的if-else有3周不同的語句

,但如果我想打開file2.php和如果usercode=3我想打開file3.php

任何人都知道php if-elseif-else/if-else代碼與該語句? 我太累了,使之與3個語句代碼

對不起我的英文不好的語言或語法

+1

嗯,你已經完全描述你會怎麼寫的那些條件。哪裏有問題?你現在的代碼是怎樣的? – Rizier123

+0

如果($用戶代碼== 1){ ///開放1 } ELSEIF($用戶代碼== 2){ ///開2 } ELSEIF($用戶代碼== 3){ ///開3 } http://php.net/manual/en/control-structures.elseif.php '使用switch語句是better' –

+0

試試這個https://3v4l.org/qMtpL也閱讀本http://php.net/manual/en/control-structures.elseif.php – Dave

回答

1

好,你可以這樣做:

if($usercode==1){ 
    //open file file1.php 
}else if($usercode==2){ 
    //open file file2.php 
}else if($usercode==3){ 
    //open file file2.php 
}else{ 
    // no file to open (this is default condition) 
} 
+0

omg,非常感謝你。你幫助我瞭解這段代碼。非常感謝你..... :)我喜歡它^ _^ –

+0

如果它的工作,然後PLZ票也; –

+0

如何投票?我是一個新手堆棧溢出 –

1

使用if/elseif read this for else if

if ($usercode == 1) 
{ 
     //Open file1 
} 
else if ($usercode == 2) 
{ 
     //Open file2 
} 
else if ($usercode == 3) 
{ 
     //Open file2 
} 

開關

switch ($usercode) 
{ 
     case 1: 
      //Open file1 
      break; 

     case 2: 
      //Open file2 
      break; 

     case 3: 
      //Open file3 
      break; 
} 
+0

感謝您的代碼:) –