DEV Community

Judith ☁ Oiku
Judith ☁ Oiku

Posted on

2 1

Difference between the assignment , equality & identity operator in PHP

There are several operators used in PHP to carry out programming operations.
= is the assignment operator, this assigns a value

e.g $x = 'hello world

== is the equality operator , it is used to test for equality

<?php
    $day = "Monday";
        if ($day == "Monday") echo "It is work day" 
?>
Enter fullscreen mode Exit fullscreen mode

Since $day = Monday and satisfies the condition, we have the output - It is work day

=== is the identity operator that is use to test if they are equal and of the same type

<?php
    $a = "1000";
    $b = 1000;
        if ($a === $b) 
            {
                echo "identical" ;
            } 
        else 
        {
            echo  "not identical"
        }
?>
Enter fullscreen mode Exit fullscreen mode

outputs not identical because $a is a string and $b is numerical, in other words they are of different type.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay