< PHP Programming

The operators for comparison in PHP are the following:

OperatorNameReturns true, if…
==equalleft & right side equals
===identical== is true, and both sides have the same type
!=not equalleft & right are not equal after type juggling
<>not equalsynonym of !=
!== not identical!= is true, or their types differ
<>not equalsynonym of !=
<less thanleft side is strictly less than right side
>greater thanleft side is strictly greater than right side
<=less than or equal toleft side is less than or equal to right side
>=greater than or equal toleft side is greater than or equal to right side
<=>spaceshipinteger less than, equal to, or greater than zero when left side is respectively less than, equal to, or greater than right side (≥ PHP 7).
$a ?? $b
?? $c
null coalescingfirst operand from left to right that exists and is not NULL. NULL, if no values are defined and that not NULL (≥ PHP 7).

Example of comparisons

This example sets and prints arrays.

PHP Code:

<?php
$value1 = 5;
$value2 = 7;

if ($value1 == $value2) {
 print('value1 is equal to value2');
} else {
 print('value1 is unequal to value2');
}
?>

PHP Output:

value1 is unequal to value2

HTML Render:

value1 is unequal to value2
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.