faqts : Computers : Programming : Languages : PHP : kms : General

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 7 people (86%) answered Yes
Recently 3 of 4 people (75%) answered Yes

Entry

Why does 0 == 'hello' in PHP?
Does PHP use types when doing comparisons?

Feb 7th, 2000 05:12
Nathan Wallace, Rasmus Lerdorf


Sure it should.  PHP is a loosely typed language.  This is how loosely
typed languages work.  You need to be able to compare 1 to "1" for
example.  The integer equivalent of "hello" is 0 and thus 0 ==
"hello".  If you want a string comparison, force both args to be strings
or use strcmp().

In PHP 4 there is a new operator === which does a strict compare.