equals sign – PHP Reference Book Blog https://phpreferencebook.com/ PHP Reference: Beginner to Intermediate PHP5 Sun, 01 Oct 2017 17:21:19 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.13 Equal Sign in PHP: Equality and Not Equals https://phpreferencebook.com/samples/equal-sign-operators/ https://phpreferencebook.com/samples/equal-sign-operators/#comments Wed, 25 Feb 2009 17:53:57 +0000 https://phpreferencebook.com/?p=153 Continue reading Equal Sign in PHP: Equality and Not Equals]]> The PHP equal sign can be used to assign the value of variable as well as evaluate a variable as part of an if-else statement or other conditional statement. However, there are subtle differences that are important for ensuring your PHP code is as accurate as possible. The following samples are from page 22.

The Equal Sign

Assignment ( = ): Assigns the value on the right to the variable on the left
Equality ( == ): Checks if the left and right values are equal
Identical ( === ): Checks if the left and right values are equal AND identical (same variable type)

Example:

$a = 1; // Sets the value of $a as the integer 1
$b = TRUE; // Sets the value of $b to the boolean TRUE
if ($a == $b){
echo 'a is equal to b.';
}
if ($a === $b){ // compare VALUE and data type: if $a(integer) === $b(boolean)
echo 'a is identical and equal to b.';
}
a is equal to b. 

Not ( ! ), Not Equal to ( != ), Not Identical to ( !== )

Used in conditional statements to evaluate as true a FALSE result of an expression or if a value is NOT equal to the second value.

Example:

$a = 1;
if (!isset($a)){ // If the variable $a is NOT set then...
echo '$a is not set'; // The expression is TRUE if it is NOT set
// Since there is no ELSE statement, nothing is displayed
}
if ($a != 0){
echo '$a does not equal zero';
}
$a does not equal zero

]]> https://phpreferencebook.com/samples/equal-sign-operators/feed/ 4