Sobes.tech
Junior

What is the difference between the equality operator '==' and the strict equality operator '===' in PHP?

sobes.tech AI

Answer from AI

The == (equality) operator compares the values of operands after converting them to the same type.

The === (strict equality) operator compares both the values and their types without type conversion.

Examples:

<?php
$a = 5;
$b = "5";
$c = 5;

// Equality: true, because "5" is converted to the number 5
var_dump($a == $b);

// Strict equality: false, because the types int and string are different
var_dump($a === $b);

// Strict equality: true, because the values and types are the same
var_dump($a === $c);