$a = true ? 'true' : 'false'; echo $a; $b = (1 > 2) ? 'true' : 'false'; echo $b; echo ($a && $b) ? 'true':'false'; 

    3 answers 3

    You do not have true and false, but the text is 'true', 'false'. Quotes take away.

    • Thank you, I understand) - Dima

    An empty string and '0' when casting to bool give false . And all the other lines when casting to bool give true .

    'false' is true .

    PHP: Booleans / Converting to boolean

    • 3
      Well, not "it is true ", but "works like true " or there "has the same effect as true ." Although the Orwellian connotation is good. - VladD
    • one
      and I really thought, is PHP really so crooked that 'true' and 'false' in quotes are given. Thank you, reassured) - Nick Volynkin ♦

    The && operator works differently for strings.

     echo (true && false) ? 'true':'false'; // false echo ('' && '') ? 'true':'false'; // false echo ('a' && 'c') ? 'true':'false'; // true 

    It is necessary to replace 'true' with true and 'false' with false .