What Is Meant by "Identity Comparison" in PHP?

In PHP, identity comparison refers to comparisons made using the identity comparison operators (i.e. === and !==), which compare its operands strictly.

For example, two operands are identical (or strictly equal) when their values are equal, and they're both of the same type:

$a = '8.0';
$b = '8.0';

var_dump($a === $b); // bool(true)
$a = '8.0';
$b = 8.0;

var_dump($a === $b); // bool(false)

Conversely, two operands are not identical (or strictly not equal) when their values are not equal, or they're not of the same type. For example:

$a = '8.0';
$b = 8.0;

var_dump($a !== $b); // bool(true)
$a = '8.0';
$b = '8.0';

var_dump($a !== $b); // bool(false)

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.