What is the difference between “!==” and “==!” in PHP?

Forums PHPWhat is the difference between “!==” and “==!” in PHP?
Staff asked 3 years ago

Answers (2)

Add Answer
Prince Dhameliya Marked As Accepted
Staff answered 3 years ago

!== Operator: It is called as non-identical operator.

Returns true if operands are not equal, or they are not of the same type.

Syntax:

$a !== $b

Where $x and $y are the operands.

Examples 1:

$a = true
$b = false
     
$a !== $b 

Output: true

Examples 2:

$x = array('hello', 'world', 'welcome');
  
$y = array('eat', 'work', 'sleep');
  
// return true
var_dump($x !== $y);

==! Operator: It is nothing but it can be further written as ==(!operand)

Returns true or false depending on operands. Both the operators return the Boolean values either true or false.

Syntax:

$a ==! $b

Examples 1:

$a = true
$b = false

$a ==! $b

Output: true

Examples 2:

$x = array('hello', 'world', 'welcome');
  
$y = array('eat', 'work', 'sleep');

// return false 
var_dump($x ==! $y);

 

Staff answered 3 years ago

!== Operator: The non-identical operator is what it’s called. If the operands are not equal or of the same type, it returns true.

Syntax:

$x !== $y

Where $x and $y are the operands.

==! Operator: It’s nothing, but it can also be expressed as ==(!operand), which returns true or false depending on the operands. Both operators produce either true or false boolean values.

Syntax:

$x ==! $y

Example 1: This program uses both operands and returns the output.

<?php
// PHP program to demonstrate
// !== and ==! operator

// Declare variables
$x = true;
$y = false;
$z = true;

// Using !== operator
echo "Using !== operator\n";

// Is $x not equals to $y
// so true returned
var_dump($x !== $y);

// Is $x not equals to $z
// so false returned
var_dump($x !== $z);

// Is $y not equals to $z
// so true returned
var_dump($y !== $z);

// Using ==! operator
echo "\nUsing ==! operator\n";

// Is $x equals to (!$y)
// so true returned
var_dump($x ==! $y);

// Is $x equals to (!$z)
// so false returned
var_dump($x ==! $z);

// Is $y equals to (!$z)
// so true returned
var_dump($y ==! $z);

?>

Output:

Using !== operator
bool(true)
bool(false)
bool(true)

Using ==! operator
bool(true)
bool(false)
bool(true)

Program 2:

<?php
// PHP program to demonstrate
// !== and ==! operator

// Dsclare associative array
$x = array(
  "1" => "Geeks",
  "2" => "for",
  "3" => "Geeks"
);

$y = array(
  "5" => "Tony",
  "6" => "Captain",
  "7" => "Thor"
);

// Union of $x and $y
$z = $x + $y;

// Using !== operator
echo "Using !== operator\n";

// Is $x not equals to $y
// so true returned
var_dump($x !== $y);

// Is $x not equals to $z
// so true returned
var_dump($x !== $z);

// Is $y not equals to $z
// so true returned
var_dump($y !== $z);

// Using ==! operator
echo "\nUsing ==! operator\n";

// Is $x equals to (!$y)
// so false returned
var_dump($x ==! $y);

// Is $x equals to (!$z)
// so false returned
var_dump($x ==! $z);

// Is $y equals to (!$z)
// so false returned
var_dump($y ==! $z);

?>

Output:

Using !== operator
bool(true)
bool(true)
bool(true)

Using ==! operator
bool(false)
bool(false)
bool(false)

 

Subscribe

Select Categories