Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP IF statement.....

Status
Not open for further replies.

JMay0816

Programmer
Mar 1, 2007
34
US
Is there an easier way to code this:

if $a==1 && $b==2 || $a==1 and $b==4


something like:

if $a==1 && $b IN (2,4)

don't know if PHP will allow to simply the if statement.
 
Code:
if ( ( $a==1 ) && (in_array($b, array(2,4) ))
or
Code:
if ($a==1){
  if ($b==2 || $b==4){
  }
}
 
Just for variety:

Code:
if ($a==1){
  switch ($b) {
    case 2:
    case 4:
      //do something
      break;
  }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top