When trying to get familiar with if statement in PHP, this happened. First time i tried this code below.
if(true) {echo 'true';} else {echo 'false';}
And the output was true when the condition is true. Again, when the condition is false (if(false)) it echos false.
But i tried the same, using a variable as the condition, while changing the value of the variable.
$con='false';
if($con){echo 'true';} else{echo 'false';}
At this situation the output is true even when the variable value is false or true. At the same time, the if statement working fine when 1 and 0 is used instead true and false. Why is this happening?
Aucun commentaire:
Enregistrer un commentaire