I have encounteed an issue with php treating “0” differently.
I run following script on 2 different machines:
$a = "0";
if ($a) {
echo("helo");
}
1) Local Machine -> PHP 5.2.17
-> it treated “0” as valid and print the ‘helo’
2) Server -> PHP 5.3.6
-> it treated “0” as empty/false and won’t print the ‘helo’
Is this due to the php configuration (if yes, what configuration) or php version?
That’s how it is supposed to. PHP interprets strings in boolean context. The
"0"there is equivalent to an actual0. (See also http://www.php.net/manual/en/types.comparisons.php)What you meant to test for is probably: