Open In App

Difference between “!==” and “==!” in PHP

Last Updated : 30 Apr, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

!== Operator: It is called as non-identical operator. It returns true if operands are not equal, or they are not of the same type.

Syntax:

$x !== $y

Where $x and $y are the operands.

==! Operator: It is nothing but it can be further written as ==(!operand) which returns true or false depending on operands. Both the operators returns the boolean values either true or false.

Syntax:

$x ==! $y

Examples:

Input: $x = true
       $y = false
Operator: $x !== $y 
Output: true

Operator: $x ==! $y
Output: true

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)


Similar Reads

Difference and Similarities between PHP and C
PHP is a server-side scripting language designed specifically for web development. It can be easily embedded in HTML files and HTML codes can also be written in a PHP file. The thing that differentiates PHP from a client-side language like HTML is, PHP codes are executed on the server whereas HTML codes are directly rendered on the browser. C is a
3 min read
Difference between JavaScript and PHP
In this article, we will know about Javascript &amp; PHP, along with understanding their significant differences. A long time before, most people used to think PHP is a server-side language and Javascript as client-side language as it was only executed in web browsers. But after V8, Node and other frameworks came, Javascript is capable of doing a l
4 min read
Difference between try-catch and if-else statements in PHP
The try and catch are used in PHP for handling exceptions like other languages such as C++, Java, etc. An exception is unexpected result or unexpected state of a program that can be handled by the program itself. To handle this kind of unexpected results in PHP, try and catch are used. For more details, visit Exception Handling in PHP. Similarly, P
5 min read
Difference between isset() and array_key_exists() Function in PHP
isset() function The isset() function is an inbuilt function in PHP which checks whether a variable is set and is not NULL. This function also checks if a declared variable, array or array key has null value, if it does, isset() returns false, it returns true in all other possible cases. Syntax: bool isset( $var, mixed ) Parameters: This function a
2 min read
Difference between bindParam and bindValue in PHP
PDOStatement::bindParam() Function The PDOStatement::bindParam() function is an inbuilt function in PHP that is used to bind a parameter to the specified variable name. This function bound the variables, pass their value as input, and receives the output value, if any, of their associated parameter marker.Syntax: bool PDOStatement::bindParam ( $par
3 min read
What is the difference between the | and || or operator in php?
'|' Operator It is a bitwise OR operator. This operator is used to set the bits of operands if either a or b or both are set. It means the value of the bit will be set to 1. A B A | B 0 0 0 0 1 1 1 0 1 1 1 1 Syntax: $a | $b Program: &lt;?php $a = 3; $b = 10; echo $a | $b; ?&gt; Output: 11 Explanation: In above example, given two values, a = 3 and b
2 min read
What is the difference between public, private, and protected in PHP?
Public, private and protected are called access modifiers. Just like C++, PHP also have three access modifiers such as public, private and protected. The visibility of a property, a method or a constant can be defined by prefixing the declaration with these keywords. If the class member declared as public then it can be accessed everywhere.If the c
3 min read
Difference between require-dev and require in PHP?
Before going to understand the difference between require and require_dev first understand what is require and require_dev. require: These are must packages for the code to run. It defines the actual dependency as well as package version. require_dev: It defines the packages necessary for developing the project and not needed in production environm
3 min read
What is the difference between HTTP_HOST and SERVER_NAME in PHP?
HTTP_HOST: It is fetched from HTTP request header obtained from the client request Example: Website: https://www.geeksforgeeks.org HTTP_HOST: www.geeksforgeeks.org HTTP_SERVER: It is fetched from the server name based on the host configuration. Example: Website: https://www.geeksforgeeks.org HTTP_SERVER: Display the server name HTTP_HOST SERVER_NAM
2 min read
What is the difference between is_a() function and instanceof in PHP?
is_a() Function The is_a() is a built-in function in PHP which is used to check whether a given object is of a given class or not. It also checks if the given class is one of the parents of the given object or not. Syntax: bool is_a( $object, $class_name, $allow_string ) Parameters: This function accepts three parameters as mentioned above and desc
3 min read