PHP If Statement with Multiple Conditions PHP If Statement with Multiple Conditions php php

PHP If Statement with Multiple Conditions


An elegant way is building an array on the fly and using in_array():

if (in_array($var, array("abc", "def", "ghi")))

The switch statement is also an alternative:

switch ($var) {case "abc":case "def":case "hij":    echo "yes";    break;default:    echo "no";}


if($var == "abc" || $var == "def" || ...){    echo "true";}

Using "Or" instead of "And" would help here, i think


you can use in_array function of php

$array=array('abc', 'def', 'hij', 'klm', 'nop');if (in_array($val,$array)){  echo 'Value found';}