brentmoeller Posted March 8, 2011 Share Posted March 8, 2011 $a === $b if $a is equal to $b, and of the same type when would you ever need to use this operator? I mean if its not == then its going to be false so why even test if its the same type. and if it is == then in theory it has to be the same type so why test it? Am i completely over looking something? Link to comment https://forums.phpfreaks.com/topic/230043-help-me-understand-this-operator/ Share on other sites More sharing options...
dk4210 Posted March 8, 2011 Share Posted March 8, 2011 Hi Brent, The difference is that == will return TRUE whether the two operands have the same value or not. === evaluates to TRUE if the two operands have the same value and are the same type. 99% of the time I just use == . I've never used === Link to comment https://forums.phpfreaks.com/topic/230043-help-me-understand-this-operator/#findComment-1184789 Share on other sites More sharing options...
mikecampbell Posted March 8, 2011 Share Posted March 8, 2011 When PHP tests variables of different types with ==, it converts them to be compatible. If you compare (0 == false), it evaluates to true. Same if you compare ("" == false). However, (0===false) and (""===false) both evaluate to false. Link to comment https://forums.phpfreaks.com/topic/230043-help-me-understand-this-operator/#findComment-1184791 Share on other sites More sharing options...
Pikachu2000 Posted March 8, 2011 Share Posted March 8, 2011 It's indispensable for use with a function that can return either an integer or a boolean true/false. See the manual entry for strpos(), for example. Link to comment https://forums.phpfreaks.com/topic/230043-help-me-understand-this-operator/#findComment-1184793 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.