[PHP] Whats the difference?

= is the assignment operator. It's used to assign a value to a variable, for example:
Code:
$bar = 1337;
$foo = $bar;
It returns the value that was assigned to the variable on the left, so the following code has the same effect:
Code:
$foo = ($bar = 1337);

== is the comparison operator. It's used to compare two values, and returns true if they are equal, false otherwise, for example:
Code:
$boolean = $foo == $bar; // $boolean is set to true if $foo and $bar are equal

if ($foo == $bar)
{
    // do something
}
 
Inquisitor's second point looks useless, but is actually really useful when you want to initialise a load of variables to the same value:

Code:
$foo = $bar = $baz = $mung = null;
 
Back
Top Bottom