PHP Conditional Operators

Like any other programming language, If and switch conditional statements are used extensively in PHP also.

An If condition allows execution of the conditional code in one of two possible ways, ie if condition is true or if condition is false.

if condition is a control operator that checks a particular condition input and can perform one of two case ie

  • 1.   input condition is true

  • 2.   input condition is false

A switch condition allows execution in a branched way as per the input case conditions set.

Switch case is a multiple branched conditions. It can execute based on the input case value.

Unlike the if condition, switch can have multiple cases.

Switch condition works on a specific type of input, like a integer based conditions,char based, etc



$x = 32;
$y = 867;

echo "TRUE condition: ".$x. " is greater than ".$y."<br>";
echo "FALSE condition: ".$x. " is smaller than ".$y."<br>";

/// SWITCH case


case 1:

echo "case 1 execution <br>";

case 2:
echo "case 2 execution <br>";

case 3:
echo "case 3 execution <br>";



FALSE condition: 32 is smaller than 867
case 3 execution 

Related Tutorials