PHP Why does this && not trigger as false?


This is because if you use && both conditions must be true. If any one condition becomes false then the overall condition evaluates to false.

The PHP code is as follows −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<?php
   $firstCondition= "John";
   $secondCondition = "David";
   if ($firstCondition == "John" && $secondCondition == "David" && ($firstCondition == "Mike" || $firstCondition == "John")) {
      echo "The above condition is true";
   } else {
      echo "The above condition is not true";
   }
?>
</body>
</html>

Output

The above condition is true

Updated on: 20-Nov-2020

39 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements