Contents / Previous / Next


Operators

Most PHP operators work as you think they should work:

ExampleNameResult
$a = $bAssign Assign value of $b to $a.
$a == $bEqualTrue if $a is equal to $b.
$a === $bIdentical True if $a is equal to $b, and of same type.
$a != $bNot equalTrue if $a is not equal to $b.
$a !== $bNot identical True if $a is not equal to $b, or not of same type.
$a < $bLess thanTrue if $a is strictly less than $b.
$a > $bGreater thanTrue if $a is strictly greater than $b.
$a <= $bLess than or equal to True if $a is less than or equal to $b.
$a >= $bGreater than or equal to True if $a is greater than or equal to $b.
$a + $bAdditionSum of $a and $b.
$a - $bSubtractionDifference of $a and $b.
$a * $bMultiplicationProduct of $a and $b.
$a / $bDivisionQuotient of $a and $b.
$a % $bModulusRemainder of $a divided by $b.
$a and $bAndTrue if both $a and $b are true.
$a or $bOrTrue if either $a or $b is true.
$a xor $bXorTrue if either $a or $b is true, but not both.
! $aNotTrue if $a is not true.
$a && $bAndTrue if both $a and $b are true.
$a || $bOrTrue if either $a or $b is true.


PHP supports C-style pre- and post-increment and decrement operators (e.g., "++$a;" does a pre increment) and the conditional "?:" (or ternary) operator:

(expr1) ? (expr2) : (expr3); This expression evaluates to expr2 if expr1 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE.


Error Control Operators

PHP supports one error control operator: the at sign "@". When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.
If the track_errors feature is enabled, any error message generated will be saved in the global variable $php_errormsg. This variable will be overwritten on each error, so check early if you want to use it.


Execution Operators

PHP supports one execution operator: backticks (``). Note that these are not single-quotes! PHP will attempt to execute the contents of the backticks as a shell command; the output will be returned. and can be assigned to a variable. Example: $output = `ls -al`; echo "<pre>$output</pre>"; Note: The backtick operator is disabled when safe mode is enabled.
See also system(), passthru(), exec(), popen(), and escapeshellcmd().