I wonder how PHP handles true/false comparison internally.
I understand that true is defined as 1 and false is defined as 0.
When I do if("a"){ echo "true";}
it echos "true". How does PHP recognize "a" as 1 ?
This is covered in the PHP documentation for booleans and type comparison tables.
When converting to boolean, the following values are considered FALSE:
FALSE
itself0
(zero)0.0
(zero)'0'
NULL
(including unset variables)Every other value is considered TRUE.