Difference between "=" and "=="

Posted on 2006-03-28
Last Modified: 2010-08-05
I am just making sure I understand this correctly. "=" is only to be used when assigning value, whereas "==" is used to check if something equals another thing? Is this correct?

Question by:stormist
    LVL 10

    Accepted Solution

    When you asigned something like
    $a = 1; then

    echo $a displays 1

    however you use == in statements to compair


    If ($a == 1) {
      echo 'Statement is true';
    } else {
      echo 'Statement is false';

    So yes you are correct.
    LVL 33

    Expert Comment

    And just to throw a little more confusion in,
    == means compare the values.  Variables will be cast to the relevant type.  (8 == '8') returns true.
    === means compare the values and types.  No casting occurs.  (8 === '8') returns false.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now