Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between == and === in php [duplicate]

Tags:

php

Possible Duplicate:
The 3 different equals

Is there any difference between == and === in php? both seem to work fine for me when i use them in a conditional statement. I am very new to programming in PHP. Please consider this and answer in simple words.

like image 559
user791180 Avatar asked Jun 11 '11 15:06

user791180


People also ask

What is difference == and === in php?

== Operator: This operator is used to check the given values are equal or not. If yes, it returns true, otherwise it returns false. === Operator: This operator is used to check the given values and its data type are equal or not. If yes, then it returns true, otherwise it returns false.

What is the difference between double == and triple === equals?

Double Equals ( == ) checks for value equality only. It inherently does type coercion. This means that before checking the values, it converts the types of the variables to match each other. On the other hand, Triple Equals ( === ) does not perform type coercion.

What is the difference between the == and === operators?

The main difference between the == and === operator in javascript is that the == operator does the type conversion of the operands before comparison, whereas the === operator compares the values as well as the data types of the operands.

Which is faster == or === PHP?

Equality operator == converts the data type temporarily to see if its value is equal to the other operand, whereas === (the identity operator) doesn't need to do any type casting and thus less work is done, which makes it faster than ==.


2 Answers

  • $a == $b

Equal true: if $a is equal to $b, after type juggling.


  • $a === $b

Identical true: if $a is equal to $b, and they are of the same type.

like image 52
evilone Avatar answered Oct 01 '22 03:10

evilone


Identical:

$a === $b

TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)

Equal:

$a == $b

TRUE if $a is equal to $b after type juggling.

Read here for more: http://www.php.net/manual/en/language.operators.comparison.php

like image 30
check123 Avatar answered Oct 01 '22 03:10

check123