#13. PHP Logical Operators

 Logical Operators


AND Operator Syntax:

Run only when both condition must be true

if(condition 1 && condition 2)

{

    Statements

}

Run Code:

<?php

$age = 20;

if ($age >= 18 && $age <= 25)    // also use (and) 

{

    echo "You are Eligible";

}

?>

OR Operator Syntax:

Run only when both conditions must be False

if(condition 1 || condition 2)

{

    Statements

}

Run Code:

<?php

$age = 30;

if ($age >= 18 || $age <= 25)    // also use (or) 

{

    echo "You are Eligible";

}

?>

Not Operator Syntax:

Opposite conditions

if(!(condition))

{

    Statements

}

Run Code:

<?php

$age = 20;

if(! ($age >= 18))     

{

    echo "You are Eligible";

}

?>

XOR Operator Syntax:

if(condition 1 xor condition 2)     // T = T => F - F = F => F - T = F => T

{

    Statements

}

Run Code:

<?php

$age = 30;

if ($age >= 18 xor $age <= 25)   

{

    echo "You are Eligible";

}

?>

Comments

Popular posts from this blog

#30. PHP Recursive Function