Why is array === array equal to true in PHP?

In php === there is an identical comparison operator, i.e. checks if two variables have the same values ​​and are of the same type. But why does array("asdf") === array("asdf") return true? I think both of them create new arrays with the same contents (please correct me if I am wrong).

+4
source share
3 answers

The simple answer is: array("asdf") === array("asdf") returns true since two arrays are compared:

  • have the same key / value pairs,
  • each of the same types and
  • in the same order.

What does array() === array() mean.

Good reading

Array operators

+4
source

Equals $a == $b TRUE if $a equals $b after type manipulation.

2 == "2"

Identical $a === $b TRUE if $a is equal to $b and they are of the same type.

array ("asdf") === array ("asdf")

Not equal to $a != $b TRUE if $a not equal to $b after type manipulation.

2! = "3"

Not equal to $a <> $b TRUE if $a not equal to $b after type manipulation.

2 <> "3"

Not identical $a !== $b TRUE if $a not equal to $b , or they are not of the same type.

array ("asdf")! == "asdf"

Less than $a < $b TRUE if $a strictly less than $b .

<p> 99 <100

Greater than $a > $b TRUE if $a strictly greater than $b .

100> 99

Less than or equal to $a <= $b TRUE if $a less than or equal to $b .

0.32 <= 0.54

Greater than or equal to $a >= $b TRUE if $a greater than or equal to $b .

2> = 2

Read this manual about comparison operators in PHP.

+2
source

Here is your answer

$ a === $ b Identification is TRUE if $ a and $ b have the same key / value pairs in the same order and of the same type.

Php Manual-Operators

+1
source

All Articles