Why is ($ages >= 21 && $ages < 70) not the same as ($ages >= 21 && 70 > $ages)?

If I write ($ages >= 21 && $ages < 70) it will be - true, if I write ($ages >= 21 && 70 > $ages) it will be - false. From the point of view of mathematics, $ages < 70 is the same as 70 > $ages. However, “&&” thinks differently.

From a mathematics point-of-view they are not the same. Example someone who is 69 years old will never be greater than 70 until they are 71.

$ages = 69
$ages < 70 and 70 > $ages = 69 < 70 and 70 > 69
($ages >= 21 && $ages < 70) - true
($ages >= 21 && 70 > $ages) - false

if ($ages < 70 && $ages> 70) {
  echo "Can NEVER BE TRUE";
} else {
  echo "False";
}

Both lines of code result in true values, just tested -

$ages = 69;
var_dump($ages >= 21 && $ages < 70); // - true
var_dump($ages >= 21 && 70 > $ages); // - true

If you are basing this result on the first code you posted, which has now been edited out of the post, you have 70<$ages in the alternate logic, not 70 > $ages

Sponsor our Newsletter | Privacy Policy | Terms of Service