Page 1 of 1

How to make this work

Posted: Mon Sep 16, 2002 6:46 pm
by stickman373
Is there a better way to do something like this and is this the correct way to do if statements and the correct way to do Or

Code: Select all

if ($f == 43 | 2 | 56 | 38) {

//Do stuff

} else {

if ($f == 34 | 53 | 4 | 9) {

//do other stuff 

} else {

if ($f == 3 | 10 |  {

//do more crap

} else {

//other things

          }  
      }
   }
}
Basically what i want it to do is if $f is 43 or 2 or 56 or 38 it does one thing but if it's 34 or 53 or 4 or 9 it does something else and if it's 3 or 10 or 8 it should do something else, but it seems to be doung the first if statement no matter what $f is.

Posted: Mon Sep 16, 2002 6:57 pm
by hob_goblin

Code: Select all

switch($f){
 case 43:
 case 2:
 case 56:
 case 38:
 echo 'its either 43,2,56, or 38';
 break;
 case 34:
 case 53:
 case 4:
 case 9:
 echo 'its either 34,53,4, or 9';
 break;
 case 3:
 case 10:
 case 8:
 echo 'its either 3,10 or 8';
 break;
 default:
 echo 'none of those.';
 }
http://www.php.net/switch ;)

Posted: Tue Sep 17, 2002 1:12 am
by dusty

Code: Select all

$nums = array("43","2","56","38");
$nums2 = array("34","53","4","9");

if(in_array($f,$nums)) {
  //Do stuff
} elseif(in_array($f,$nums2)) {
  //Do stuff
} else {
  //Do stuff
}

Posted: Tue Sep 17, 2002 8:25 pm
by stickman373
thanks a lot dusty, that worked perfectly :D