The Wayback Machine - https://web.archive.org/web/20241121022117/https://www.geeksforgeeks.org/how-do-the-php-equality-double-equals-and-identity-triple-equals-comparison-operators-differ/
Open In App

How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?

Last Updated : 07 Jan, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Equal Operator ==

The comparison operator called Equal Operator is the double equal sign “==”. This operator accepts two inputs to compare and returns true value if both of the values are same (It compares only value of variable, not data types) and return a false value if both of the values are not same. 
This should always be kept in mind that the present equality operator == is different from the assignment operator =. The assignment operator changes and assigns the variable on the left to have a new value as the variable on right, while the equal operator == tests for equality and returns true or false as per the comparison results.
Example: 
 

php




<?php
 
// Variable contains integer value
$x = 999;
 
// Variable contains string value
$y = '999';
 
// Compare $x and $y
if ($x == $y)
    echo 'Same content';
else
    echo 'Different content';
?>


Output: 

Same content

 

Identical Operator ===

The comparison operator called as the Identical operator is the triple equal sign “===”. This operator allows for a much stricter comparison between the given variables or values. 
This operator returns true if both variable contains same information and same data types otherwise return false.
Example: 
 

php




<?php
 
// Variable contains integer value
$x = 999;
 
// Variable contains string value
$y = '999';
 
// Compare $x and $y
if ($x === $y)
    echo 'Data type and value both are same';
else
    echo 'Data type or value are different';
?>


Output: 

Data type or value are different

 

In the above example, value of $x and $y are equal but data types are different so else part will execute.
 



Previous Article
Next Article

Similar Reads

How Object.is() method differ from strict equality (===) ?
Object.is():The Object.is() method is used to compare two values for equality.It returns true if the values are the same, and false otherwise.It handles special cases such as -0 and NaN differently compared to strict equality (===).Specifically, Object.is() distinguishes between +0 and -0, and between different NaN values.Example: Below is an examp
1 min read
Strict Equality(===) Comparison Operator in JavaScript
JavaScript Strict Equality Operator is used to compare two operands and return true if both the value and type of operands are the same. Since type conversion is not done, so even if the value stored in operands is the same but their type is different the operation will return false. Syntax: a===b Example 1: In this example, we will compare the val
2 min read
Equality(==) Comparison Operator in JavaScript
In JavaScript, the Comparison Equality Operator is used to compare the values of the operand. The comparison operator returns true only if the value of two operands are equal otherwise it returns false. It is also called a loose equality check as the operator performs a type conversion when comparing the elements. When the comparison of objects is
2 min read
Difference between double equal vs triple equal JavaScript
Double equal: The double equal('==') operator tests for abstract equality i.e. it does the necessary type conversions before doing the equality comparison. Triple equal: The triple equal('===') operator tests for strict equality i.e it will not do the type conversion hence if the two values are not of the same type, when compared, it will return fa
2 min read
Double-Dot “..” vs. Triple-Dot “…” in Git Commit Ranges
Git, the distributed version control system, is a powerful tool for tracking changes in source code during software development. Among its many features, the syntax for specifying commit ranges is important for managing and understanding changes in your repository. Two such syntaxes are the double-dot `..` and the triple-dot `....` While they might
4 min read
SASS Equality Operators
Compatibility: Dart Sass is fully compatible with using equality operators, whereas LibSass and older versions of Ruby Sass (older than version 4.0.0) consider numbers as equal even if they have different units or if one has a unit and the other does not. This behavior was not useful and hence the newer versions have removed this as it violates tra
3 min read
Does JavaScript Operators like or ( || ), and ( && ), null coalescing ( ?? ) makes Weak Comparison?
JavaScript operators like logical OR (||), logical AND (&&), and null coalescing (??) are used for making conditional evaluations and performing logical operations in JavaScript. While these operators are commonly used for controlling the flow of the code execution and handling values in the different scenarios it's essential to understand
2 min read
What are Comparison Operators in JavaScript ?
Comparison operators in JavaScript are used to compare two values and return a boolean result (true or false). They include operators such as ==, ===, !=, !==, >, <, >=, and <=. Example: Here, the > (greater than) the operator compares the values of a and b. Since a is not greater than b, the expression a > b evaluates to false, w
1 min read
JavaScript Comparison Operators
JavaScript comparison operators are essential tools for checking conditions and making decisions in your code. They are used to evaluate whether a condition is true or false by comparing variables or values. These operators play a crucial role in logical expressions, helping to determine the equality or differences between values. In this article,
6 min read
What is VRML and how does it differ from HTML ?
VRML (Virtual Reality Modeling Language) — VRML (pronounced as “V-R-M-L” or “ver-mal”) is a modeling language which helps to create platform-independent 3D objects and interactive scenes on a web page. It was first introduced in 1994 at the first World Wide Web conference by Mark Pesce, Tony Parisi, and others. VRML had initially stood for Virtual
3 min read
How does rem differ from em in CSS ?
In this article, we will learn about rem & em in CSS, how they differs from each other. The em and rem are the relative length CSS font-size units that can be used in CSS documents to make a specific element's font size relative to its parents. The em is a CSS font-size unit relative to its directly linked parent, rem is in relation with the fo
4 min read
How does JSX differ from HTML ?
JSX, a syntax extension for JavaScript, allows the creation of user interfaces similar to HTML but within JavaScript. Unlike HTML, JSX enables the embedding of JavaScript expressions and facilitates the creation of reusable components, promoting a more dynamic and efficient approach to web development. JSX ( JavaScript XML)JSX stands for JavaScript
3 min read
How does a pure component differ from a functional component?
React provides two main types of components: pure components and functional components. Understanding the differences between these two types is important for effective React development. In this article, we will learn about pure components and functional components, along with discussing the significant distinction that differentiates between pure
4 min read
How does SSR(Server-Side Rendering) differ from CSR(client-side rendering) ?
Server-Side Rendering (SSR) and Client-Side Rendering (CSR) are two different approaches used in web development to render web pages to users. Each approach has its own set of advantages and disadvantages. In this article, we will learn about the difference between SSR and CSR with examples and features. Table of Content Server-Side Rendering (SSR)
4 min read
How does a Pure Component Differ from a Regular Component ?
In React, components are the building blocks of user interfaces. They encapsulate the UI logic and render the UI elements based on the input data. React offers different types of components, including regular components and Pure Components. Table of Content Components in ReactRegular ComponentsBenefits of Regular ComponentsWhen to use Regular Compo
4 min read
How does Redux Saga Differ from Redux Thunk ?
In Redux, middleware plays a crucial role in managing asynchronous actions. Redux Saga and Redux Thunk are two popular middleware libraries used for handling side effects in Redux applications. While both serve similar purposes, they differ significantly in their approach and capabilities. In this article, we'll see the differences between Redux Sa
5 min read
What are triple-slash Directives in TypeScript ?
Triple-slash directives in TypeScript are special comments that are used to provide instructions to the TypeScript compiler (tsc) or the IDE (Integrated Development Environment) about how to process a TypeScript file. These directives start with three forward slashes (///) and are typically placed at the top of a TypeScript file. Triple-slash direc
6 min read
What are these triple dots (...) in JavaScript ?
In JavaScript, there are multiple ways in which we can assign the value of one object to another. Sometimes we do not know the exact number of arguments that are to be assigned. In this case, the triple dots are used.  The triple dots are known as the spread operator, which takes an iterable(array, string, or object) and expands the iterable to ind
4 min read
JavaScript SyntaxError - Test for equality (==) mistyped as assignment (=)?
This JavaScript warning test for equality (==) is mistyped as an assignment (=)? occurs if by assignment (=) is used in place of equality (==). Message: Warning: SyntaxError: test for equality (==) mistyped as assignment (=)? Error Type: SyntaxError: Warning which is reported only if javascript.options.strict preference is set to true. Cause of err
1 min read
What is object equality in JavaScript ?
JavaScript provides us with a number of ways to check if two objects are equal. Let us demonstrate how to check whether two objects are equal. There are three types of equality - Referential equality.Shallow equality.Deep equality.Referential equality: We can say two objects are referentially equal when the pointers of the two objects are the same
4 min read
TypeScript Equality Narrowing Type
In this article, we are going to learn about Equality narrowing Type in Typescript. TypeScript is a popular programming language used for building scalable and robust applications. In TypeScript, "equality narrowing" refers to the process of narrowing the type of a variable based on equality checks or comparisons. TypeScript can use equality checks
4 min read
How to Compare Objects for Equality in JavaScript?
When working with JavaScript it is common to compare objects for equality. we will explore various approaches to compare objects for equality in JavaScript. These are the following approaches: Table of Content Using JSON.stringifyUsing Lodash's isEqual() MethodUsing Object.keys() and Array.every()Using Object.entries() and Array.every()Using JSON.s
3 min read
Equality for two JavaScript objects
Comparing two JavaScript objects for equality involves checking if they have the same properties with the same values. This process is more complex than comparing primitive values due to the objects' reference-based nature and potential nested structures in JavaScript. Below are the approaches to check the equality of two JavaScript objects: Table
2 min read
What is the difference between single-quoted and double-quoted strings in PHP?
Single or double quotes in PHP programming are used to define a string. But, there are lots of differences between these two. Single-quoted Strings: It is the easiest way to define a string. You can use it when you want the string to be exactly as it is written. All the escape sequences like \r or \n, will be output as specified instead of having a
3 min read
Underscore.js _.identity() Function
Underscore.js is a JavaScript library that makes operations on arrays, string, objects much easier and handy. The _.identity() function is used to return the exact same replica of the value given to it as the argument. This function looks useless, but is used throughout Underscore as a default iteratee. Note: It is very necessary to link the unders
2 min read
Tensorflow.js tf.initializers.identity() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. The Initializer class is the base class of all initializers in Tensorflow.js. The initializers are used to initialize the Tensors with the specific values. It returns the tensor object
2 min read
Lodash _.identity() Method
Lodash _.identity method returns the first argument it receives. Syntax:_.identity(value);Parameters: value: It can be any value.Return Value:Returns the first argument it receives. Example 1: In this example, it is returning the first parameter because of the lodash _.identity() method. C/C++ Code // Requiring the lodash library const _ = require(
1 min read
JavaScript Program to Check if a Given Square Matrix is an Identity Matrix
Given a matrix, our task is to check if a given square matrix is an Identity Matrix. An identity matrix (unit matrix) is a square matrix in which the principal diagonal elements are all one and other elements in the matrix are zero. Example:Input:[ [ 1, 0, 0] , [0, 1, 0] , [0, 0, 1]] Output: True Below are the approaches to check if a given square
3 min read
Difference between the (=), (==), and (===) operators in PHP
In PHP, the '=' operator is used for assignment, while the '==' operator is used for loose equality comparison, meaning it checks if two values are equal without considering their data types. On the other hand, the '===' operator is used for strict equality comparison, meaning it checks if two values are equal and of the same data type. = OperatorT
3 min read
PHP | Bitwise Operators
The Bitwise operators is used to perform bit-level operations on the operands. The operators are first converted to bit-level and then calculation is performed on the operands. The mathematical operations such as addition , subtraction , multiplication etc. can be performed at bit-level for faster processing. In PHP, the operators that works at bit
5 min read
Article Tags :
three90RightbarBannerImg