what does == mean in php?

== means "is equal to", not to be confused with "equals"
for example
if x = = y
is read "if x is equal to y",
so it checks to see if x is equal to y.
on the other hand
x=y
is read "x equal y" or "set x equal to y"
it defines x to be equal to y.
 
used here:

2. $counter = 0;
------------------------------------------------------
16. if ($counter == 2){
17. echo "<em>Nothing to see</em>.";

confused as when there are either 1 or 2 files in the directory, they are displayed.
 
== means "is equal to", not to be confused with "equals"
for example
if x = = y
is read "if x is equal to y",
so it checks to see if x is equal to y.
on the other hand
x=y
is read "x equal y" or "set x equal to y"
it defines x to be equal to y.
 
== means "is equal to", not to be confused with "equals"
for example
if x = = y
is read "if x is equal to y",
so it checks to see if x is equal to y.
on the other hand
x=y
is read "x equal y" or "set x equal to y"
it defines x to be equal to y.
 
== is a loose comparison operator it sees if two things are equal in value

=== is strict comparison it sees if two things are equal in value and type

Examples:

1 == 1 // The Boolean value of 1 (or true).
if(1 == 1){ return true;}

"1" == "1" // The string value of "1"
if("1" == "1"){ return true;}

0 === 0 //The Boolean value of 0 (or false)
if(0 === 0){ return true;}

all of the above will return true or Boolean of 1 not "1" but 1

if($counter == 2){
echo "<em>Nothing to see</em>";
}

will return false.
The Boolean value of 0 (or false) is not equal to the integer value of 2
 
Back
Top