30.1. Calculations and Operators

PHP supports the usual collection of standard operators, as shown in the following table:

PHP Arithmetic Operators

OperatorUse
+Addition
Subtraction
*Multiplication
/Division
%Modulus
++Increment
--Decrement

PHP supports C-style pre and post types of increment and decrement operators. The pre operators (designated by placing the operators prior to the variable, for example, --$a) perform the operation and then return the value of the variable. The post operators (designated by placing the operators after the variable, for example, $a--) return the value of the variable and then perform the operation.

PHP Assignment Operators

OperatorUse
=Assignment
+=Increment assignment
−=Decrement assignment
*=Multiplication assignment
/=Division assignment
%=Modulus assignment

PHP Comparison Operators

OperatorUse
==Is equal to
===Exactly identical, in value and type
!=Is not equal to
!==Is not identical
>Is greater than
<Is less than
>=Is greater than or equal to
<=Is less than or equal to

PHP Logical Operators

OperatorUse
&& or andAnd
|| or orOr
!Not
xorXor

PHP Bitwise Operators

Operatorbottom
&And
|Or
^Xor
~Not
<<Left shift
>>Right shift

PHP Miscellaneous Operators

OperatorUse
?:Condition operator

PHP String Operators

OperatorUse
.Concatenation
.=Concatenation assignment

PHP Array Operators

OperatorUse
+Union

PHP String Tokens

TokenCharacter
\bBackspace
\tHorizontal tab
\nLine feed
\vVertical tab
\fForm teed
\rCarriage return
\"Double-quote
\'Single-quote
\\Backslash

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.