HomeWeb application programmingPHP programmingPHP comparison syntax: equality

PHP comparison syntax: equality

The equality comparison is a fundamental operation in programming languages. In PHP, to evaluate if one expression is equal to another, use the == comparison as described in this Tech-Recipe.


if ($var1 == $var2)
echo "Yep, they're equal.";

Warning: the code inside the expression can be any valid PHP code, so if a function returns a value, you can assign that value to a variable and use the return value in a comparison. A common mistake in writing equality conditionals is using a single = instead of a double ==. The conditional expression ($var1 = $var2) assigns the value of $var2 to $var1 and always evaluates as true.

Quinn McHenry
Quinn McHenry
Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments

Cleveland Furia on How to Clear Google Activity
Sid Wohlfarth on How to Clear Google Activity
Riley Magsayo on How to Clear Google Activity
สมัครรับเครดิตฟรี ทันที on How to improve Remote Desktop Protocol Performance
Neal Wangstad on How to Clear Google Activity
Slavcho Andov on How to install Ubuntu
Slavcho Andov on How to fix bad sectors
Sheraz Ali on How to Backup Android