mardi 23 mai 2017

Why is this IF statement evaluating to false when all conditions are true?

In this case, the values for $r, $g, $b are:

r: 113
g: 113
b: 105

/

$threshold = 10;
if ((abs($r - $g) <= $threshold) && (abs($r - $b) <= $threshold) && (abs($g - b) <= $threshold))
{
  return TRUE;
}
else
{
  echo "<hr/>";
  var_dump((abs($r - $g) <= $threshold) && (abs($r - $b) <= $threshold) && (abs($g - b) <= $threshold)); //bool(false) 
  echo abs($r - $g) . "<br />"; //0
  echo abs($r - $b) . "<br />"; //8
  echo abs($g - $b) . "<br />"; //8
  echo $threshold . "<br />"; //10
  var_dump( (abs($r - $g) <= $threshold)); //bool(true)
  var_dump( (abs($r - $b) <= $threshold)); //bool(true)
  var_dump( (abs($g - $b) <= $threshold)); //bool(true)
}

This is the output

bool(false) 0
8
8
10
bool(true) bool(true) bool(true) 

If all the conditions for the IF statement are TRUE, why is it evaluating to FALSE?

Aucun commentaire:

Enregistrer un commentaire