php echo if two conditions are true

You can use the if statement in PHP to check if two conditions are true. The syntax for an if statement is as follows:

<?php

$condition1 = true;
$condition2 = true;

if ($condition1 && $condition2) {
  echo "Both conditions are true\n";
}

$condition1 = false;
$condition2 = true;

if ($condition1 && $condition2) {
  echo "Both conditions are true\n";
} else {
  echo "One of the conditions is false\n";
}

$condition1 = true;
$condition2 = false;

if ($condition1 && $condition2) {
  echo "Both conditions are true\n";
} else {
  echo "One of the conditions is false\n";
}

$condition1 = false;
$condition2 = false;

if ($condition1 && $condition2) {
  echo "Both conditions are true\n";
} else {
  echo "One of the conditions is false\n";
}

Watch a course Learn object oriented PHP

You can use && operator to check multiple conditions.

<?php

$a = 10;
$b = 20;
if ($a > 5 && $b < 30) {
  echo "Both conditions are true\n";
}

$a = 5;
$b = 20;
if ($a > 5 && $b < 30) {
  echo "Both conditions are true\n";
} else {
  echo "One of the conditions is false\n";
}

$a = 10;
$b = 35;
if ($a > 5 && $b < 30) {
  echo "Both conditions are true\n";
} else {
  echo "One of the conditions is false\n";
}

$a = 5;
$b = 35;
if ($a > 5 && $b < 30) {
  echo "Both conditions are true\n";
} else {
  echo "One of the conditions is false\n";
}

In this example, the code inside the if statement will be executed if the value of $a is greater than 5 and the value of $b is less than 30.