I
I
iOS Dav2015-12-06 07:33:27
PHP
iOS Dav, 2015-12-06 07:33:27

What is the difference between "!==", "!=", "==", "==="?

What is the difference between !==, !=, ==, ===? Which one to use?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
C
Cat Anton, 2015-12-06
@Aidosss

Type comparison table in PHP :
53bdc7efd2464a1aa19648d775a53d92.png

I
Immortal_pony, 2015-12-06
@Immortal_pony

$a === $b	 //TRUE если $a равно $b и имеет тот же тип.

Documentation - php.net/manual/ru/language.operators.comparison.php
Which one to use depends on the situation. If you want to compare only the values ​​of variables, then ==/!= is sufficient. If it is necessary to check the type of the variable, then ===/!==.

B
Baizet Tlyupov, 2015-12-06
@baizet01

The difference between != and !==, as well as == and ===, is the strictness of the comparison.
For example
$a = 1;
$b = "1";
$a == $b will return TRUE, since types are cast to a common one, respectively, != in this situation will return FALSE,
and $a === $b will return FALSE, since data types will also be compared.
This is a rough explanation, but the principle of operation should be clear.

X
xmoonlight, 2015-12-06
@xmoonlight

Если кратко (только часто встречающиеся в повседневной практике):
=== для СТРОГОЙ проверки ТИПА и ЗНАЧЕНИЯ.
Пример: (1==='1' || 0===false) => false || false => false
== для НЕСТРОГОЙ проверки СТРОК/ЦИФР (печатных символов) с автоприведением типов.
Пример: (1=='1' && 0==false) => true && true => true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question