Загрузка...

Understanding the Difference Between == And === in PHP

Both == and === are comparison operators, but there is a difference.

== operator checks if two values are equal or not.

=== operator checks if two values and their data types are equal or not.

Let's see an example.
Two values are equal and "Equal" will be returned.
$no1 = 25;
$no2 = 25;
echo $no1 == $no2 ? "Equal" : "Not Equal";

Extend this example and see it again.
Two values are equal, but types are different, but still "Equal" will be returned.
$no1 = 25;
$no2 = "25";
echo $no1 == $no2 ? "Equal" : "Not Equal";

Two values and their types are equal and "Equal" will be returned.
$no1 = 25;
$no2 = 25;
echo $no1 === $no2 ? "Equal" : "Not Equal";

Two values equal, but their types are not equal, so "Not Equal" will be returned.
$no1 = 25;
$no2 = "25";
echo $no1 === $no2 ? "Equal" : "Not Equal";

Видео Understanding the Difference Between == And === in PHP канала PHP Explained
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки

На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.

Об использовании CookiesПринять