$a = true ? 'true' : 'false'; echo $a; $b = (1 > 2) ? 'true' : 'false'; echo $b; echo ($a && $b) ? 'true':'false'; |
3 answers
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 .
- 3Well, not "it is
true", but "works liketrue" or there "has the same effect astrue." Although the Orwellian connotation is good. - VladD - oneand 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 .
|