PHP Array operators in PHP

Array operators in PHP

array operators in php

To perform operations on arrays easily PHP array operators is a good choice. We can use Union operators, Equality operators, Identity operator, Inequality operators and Non-identity operators to perform operations on arrays in PHP. There are various types of array operators described below.

Union Array Operator (+)

Union operator is denoted by + sign. It append the array on the right side to the array on left. If both arrays have any key in common (key exist in both arrays) then elements of left side array will be considered and matching elements from right side array will be ignored.

Example :


In the above example, key “p” is common so in both operations the value of key “p” on the right side is considered and ignored of the left array.

Equality Array Operator (==)

To check if both the arrays have same elements (key value pairs) or not, Equality operator is used.

If array1 and array2 have the same elements (key value pairs) then boolean true is returned, else boolean false is returned.

Example :

Inequality Array Operator (!=)

Inequality Array Operator is used to check if both arrays have the same elements or not It returns Boolean true if arrays are not equal, Boolean false for equal arrays.

Example :

Identity Array Operator (===)

Two arrays are Identical only if the Keys and Values both are equal.

Example :

Non-identity Array Operator (!==)

Two arrays are Non-identical if the Keys and Values both are not equal.

Example :

Share your thoughts

Notify of