Operators

View saved

Arithmetic

Use familiar operators for numbers.

<?php
echo 10 + 3, "\n";
echo 10 % 3, "\n";
echo 2 ** 3, "\n";

Assignment shortcuts

Combine update and assign.

$n = 5;
$n += 2;
echo $n, "\n";

Comparisons

Prefer strict comparisons to avoid surprising coercions.

var_dump(5 === "5"); // false
var_dump(5 == "5");  // true

Logical operators

  • && / and for both true
  • || / or for either true
  • ! to negate
  • Parentheses clarify mixed expressions

Comments

One comment per signed-in account. Comments are saved with this page’s URL.