2.5. Operators

As stated earlier, an operator is a symbol that tells PHP to perform a mathematical or logical operation on one or more operands. An expression such as $result = 2 + 5 contains three operators. The $ operator lets PHP know you're using a variable named result. The = operator assigns the value on the right to the variable on the left. The + operator adds the values on each side of it.

Most operators work on two operands and are called binary operators. Others operate on only one operand and are referred to as unary operators. PHP also has one operator that works with three operands, known as the ternary operator. With some exceptions, most operators fall into five categories: arithmetic, logical, bitwise, assignment, and control. ...

Get Core PHP Programming, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.