Skip to content

Instantly share code, notes, and snippets.

@danomanion
Created March 14, 2014 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danomanion/9556877 to your computer and use it in GitHub Desktop.
Save danomanion/9556877 to your computer and use it in GitHub Desktop.
// Assign these to play around with
$a = 1;
$b = 2;
// 1. Assignment operators
$a = $b; // Assign the value of $b to $a
$a += $b; // Assign the value of $a + $b to $a
$a -= $b; // Assign the value of $a - $b to $a
$a .= $b; // Concatenate $a and $b
$a = &$b; // Make $a a reference to $b
// 2. String operators
$c = $a . $b; // Concatenate $a and $b and assign to $c
$a .= $b; // Concatenate $a and $b and assign to $a
// 3. Comparison operators
if ($a == $b) {} // Equal to
if ($a === $b) {} // Intentical to
if ($a != $b) {} // Not equal
if ($a <> $b) {} // Not equal
if ($a !== $b) {} // Not identical to
if ($a < $b) {} // Less than
if ($a > $b) {} // Greater than
if ($a <= $b) {} // Less than or equal to
if ($a >= $b) {} // Greater than or equal to
// 4. Arithmetic operators
$c = -$b; // Opposite
$c = $a + $b; // Plus
$c = $a - $b; // Minus
$c = $a * $b; // Multiply
$c = $a / $b; // Divide
$c = $a % $b; // Remainder of $a / $b (Modulus)
// 5. Incrementing operators
$a++; // Add one to $a
$a--; // Minus one from $a
// 6. Logical operators
if ($a AND $b) {} // Both $a and $b are true
if ($a && $b) {} // Both $a and $b are true
if ($a OR $b) {} // Either $a or $b is true
if ($a || $b) {} // Either $a or $b is true
if (!$a) {} // $a is not true
if ($a XOR $b) {} // Either $a or $b is true, but not both
// 7. Array operators
$c = $a + $b;
if ($a == $b) {} // Same key / value pairs
if ($a === $b) {} // Same key / value pairs in the same order and same types
if ($a != $b) {} // $a and $b do not have the same key / value pairs
if ($a <> $b) {} // $a and $b do not have the same key / value pairs
if ($a !== $b) {} // $a and $b do not have the same key / value pairs, the same order and same types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment