Today I played with PHP, and I found that the string values โโ"true" and "false" are not correctly parsed into boolean in state, for example, by considering the following function:
function isBoolean($value) { if ($value) { return true; } else { return false; } }
If I do:
isBoolean("true") // Returns true isBoolean("") // Returns false isBoolean("false") // Returns true, instead of false isBoolean("asd") // Returns true, instead of false
It seems to work only with the values โโ"1" and "0":
isBoolean("1") // Returns true isBoolean("0") // Returns false
Is there a built-in function in PHP for parsing the strings "true" and "false" in boolean?
php parsing boolean
Mark Jan 23 '11 at 17:38 2011-01-23 17:38
source share