Why does (0 == ‘Hello’) return true in PHP?

The operators == and != do not compare the type. Therefore PHP automatically converts ‘Hello’ to an integer which is 0 (intval('Hello')). When not sure about the type, use the type-comparing operators === and !==. Or better be sure which type you handle at any point in your program.

Leave a Comment