Jump to content

[SOLVED] Help understanding === vs. ==


Recommended Posts

I'm a little confused.  I see this more and more often when I look at open-source apps:

 

if(''===$var)

 

In every article, every book, that I have ever read (not that I've read nearly everything or that everything I've read was good), it's always been this:

 

if($var=='')

 

What's the difference between '===' and '==', and why put the value first instead of the variable?  Is there a performance or accuracy difference?  Is '===' case-sensitive?  How can it be more strict than '=='?  I Googled it, but some of the things I read made me more confused ...

Link to comment
https://forums.phpfreaks.com/topic/123829-solved-help-understanding-vs/
Share on other sites

If you look at it logically , you are saying

 

if variable one doesnt equal empty , then do

if($var != '')

 

or

 

if empty doesnt equal variable one , then do

if('' != $var)

 

Yeah, but logically, to me, those end up with the same result.  Either they are equal or they aren't.  2 * 3 = 6, and 6 = 3 * 2.  I was just curious if there was performance difference or something, but it sounds like I'll have to bench it to find out.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.