What is the inequality operator in php and what

青灯夜游
Release: 2023-03-10 09:36:02
Original
3435 people have browsed it

The inequality operators in php are "!=", "!==" and "<>". The "!=" and "<>" operators are completely equivalent, without any difference, and are used to compare whether the values ​​​​of two objects are equal; while the "!==" operator indicates absolute inequality. In addition to comparing values, it also Will compare types.

What is the inequality operator in php and what

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php inequality operator

Operator Name Description Instance
x != y is not equal to If x is not equal to y, return true 5!=8 Return true
x <> y is not equal to If x is not equal to y, return true 5<>8 Return true
x !== y Absolutely not equal If x is not equal to y, or they are not the same type, return true 5!= ="5" returns true

Instructions: In

php, <> and != These two are completely equivalent, without any difference. They are used to compare whether the values ​​​​of two objects are equal.

is not equal to !== In addition to comparing values, types will also be compared.

For example: 1 != '1' will return false, because the values ​​of number 1 and string 1 are equal,

1 !== '1' will return true because the two types are not equal

Example:

<?php
$x=100; 
$y="100";

var_dump($x == $y); // returns true because values are equal
echo "<br>";
var_dump($x === $y); // returns false because types are not equal
echo "<br>";
var_dump($x != $y); // returns false because values are equal
echo "<br>";
var_dump($x !== $y); // returns true because types are not equal
echo "<br>";

$a=50;
$b=90;

var_dump($a > $b);
echo "<br>";
var_dump($a <  $b);
?>
Copy after login

Output:

bool(true)
bool(false)
bool(false)
bool(true)
bool(false)
bool(true)
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the inequality operator in php and what. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template