Array Operators
×
Home Courses Community Support
Array Operators

Likely airthmetic operator used for numeric values, Array Operators used for array.

Operator '+'

<?php
$x = array("0" => "Mango", "1" => "banana"); 
$y = array("2" => "Graps", "3" => "Pineapple"); 
$z=$x+$y;
var_dump($z)
?>


In above code we have two array and passed the union of both in $z. Check the code in CodeLAB or on your PC. It will show you all the fruits in variable $z.
 

Operator '=='

This operator returns true if both array have the same value.

See below example-

<?php
$x = array("0" => "Mango", "1" => "banana"); 
$y = array("2" => "Graps", "3" => "Pineapple"); 
var_dump($x==$y)
?>

Output:

boolean false


Operator '==='

This operator returns true if both array have same values in same order and same type.

See below example-

<?php
$x = array("0" => "Mango", "1" => "banana"); 
$y = array("2" => "Graps", "3" => "Pineapple"); 
var_dump($x===$y)
?>

Output:

boolean false


Operator '!='

This operator returns true if array in left side is not equal the array in right side.

See below example-

<?php
$x = array("0" => "Mango", "1" => "banana"); 
$y = array("2" => "Graps", "3" => "Pineapple"); 
var_dump($x !=$y)
?>

Output:

boolean true

enlightenedWe can use operator '<>' instead of '!='. Both have same functionalities


Operator '!=='

Return true if array in left side is not identical to array in right side. It check both the value and the position.

See below example-

<?php
$x = array("0" => "Mango", "1" => "banana"); 
$y = array("2" => "Mango", "3" => "banana"); 
var_dump($x !== $y)
?>

 Output:

boolean true

Now if we will change the position of array element in $y to '0' and '1' then the code will return value false.

See below example-

<?php
$x = array("0" => "Mango", "1" => "banana"); 
$y = array("0" => "Mango", "1" => "banana"); 
var_dump($x !==$y)
?>

Output:

boolean false

 

← Preview

String Operators

Next →

Ternary Operator

NOTES

Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.

Courses

  • Python
  • Game Development with Unity 3D
  • Arduino
  • PCB & Circuit Designing
  • Robotics and Embedded C
  • 8051/8052 Embedded Systems
  • QuadCopter & UAV
  • MATLAB with Robotics
  • Raspberry Pi
Learn On the Go!
Get the Android App
Get the iOS App