What to do? == and === mean in PHP?

Possible duplicates:
How do the comparison operators for equality (== double equals) and identities (=== triple equals) differ?
Link - what does this symbol mean in PHP?
php is not equal! = and! ==

What are the operators !==and ===in this code snippet?

if ( $a !== null ) // do something
if ( $b === $a ) // do something
+5
source share
6 answers

They are strict type comparison operators. They not only check the meaningbut also type .

Consider a situation where you are comparing numbers or strings:

if (4 === 4) // same value and type
{
  // true
}

but

if (4 == "4") // same value and different type but == used
{
  // true
}

and

if (4 === "4") // same value but different type
{
  // false
}

This applies to both objects and arrays.

, : == ===

===,

:

+6

.

1 == 1
1 == "1"
1 === 1
1 !== "1"
true === true
true !== "true"
true == "true"

true. , @mbeckish

+13

=== .

, "1" == 1 true, "1" === 1 false. fonctions, 0 False (, strpos).

, strpos 0 0 == false

if (strpos('hello', 'hello world!'))

, , :

if (strpos('hello', 'hello world!') !== false)
+1

double = , // , // .

= - , , // - .

! ==

0

true , . : 1 === 1 "1" === 1 1 === "1" "1" === "1"

, ==,

0

==, .

if( '1' == 1 ) { echo 'yes'; }

, .

===, .

if( '1' === 1 ) { /* this will not work */ }

, '1' string, 1 - integer number

- - : D

if( (integer) '1' === 1 ) { echo 'this works'; }

'1' integer

0

All Articles