Skip to main content

//Logical Operator

Logical Operator


  1.  <?php
  2.  //Logical Operator
  3. $a = 50;
  4. $b = 30;

  5. //Logical AND
  6. //we use also  Logical NOT
  7. if (!(($a > $b) && ($a != $b))) // !(a=50 > b=30) is False && (a=50 != b=30) is True; Therefore this statement is False.
  8.                                // when both statement are True then result will be True.
  9.                               // '!'not is True statement consider False and False statement consider to True.
  10. {
  11. echo "this statement is true <br>";
  12. } else {
  13. echo "this is statement is false <br>";
  14. }

  15. //Logical OR
  16. if (($a < $b) || ($a != $b)) // (a=50 < b=30) is False || (a=50 != b=30) is True; therefore this statement is True.
  17.                         //if one(or both) statement is True then result will be True, Otherwise it returns False.
  18. {
  19. echo "this staement is true <br>"; //"echo" use for print line.
  20. } else {
  21. echo "this staement is false <br>"; //"<br>" use for linebreak.
  22. }
  23. ?>


//Execute

//Output

/*

//Logical AND

First statement is false


//Logical OR

Second statement is true

*/





                                                                                            //ThE ProFessoR