Is there a difference between $str == '' and strlen($str) == 0 in PHP?
问题 As the title says: Is there a difference between $str == '' and strlen($str) == 0 in PHP? Is there any real speed difference and is one better to use than the other? 回答1: Yes, there is an important difference. The == operator does type conversion, so it's not always going to do what you expect. For example, (0 == "") returns true. So you're making an assumption that $str is actually a string. If you're sure this is the case, or if you don't care about the conversions, then it's fine.