0

I want to request php code if-else / if-elseif-else, with this statements:

if usercode=1 i want to open file1.php, but if usercode=2 i want to open file2.php and if usercode=3 i want to open file3.php.

anyone know the php if-elseif-else/if-else code with that statements? i'm so tired to make the code with that 3 statements

sorry for my bad english language or grammar

3

2 Answers 2

1

well you can do like this :

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)
}
Sign up to request clarification or add additional context in comments.

8 Comments

omg, thank you very muchh. you help me with that code. Thank you very much again..... :) i enjoy it ^_^
Click on the upper triangle where it is written zero(0) in bold on my answer
@arigohafnan click on up cursor meta.stackexchange.com/questions/173399/…
@aman What do you need this last else for, in this code sample?
@rafal-kozlowski this is the default condition for example if mistakenly user passes the some other value apart from 1,2,3 the the block of code go in the else block and you can alert that user saying ( hey that not the valid input plese pass 1,2 or 3)
|
1

Using 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

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

      case 2:
            //Open file2
            break;

      case 3:
            //Open file3
            break;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.