2.6. Operators

PHP contains three types of operators: unary operators, binary operators, and one ternary operator.

Binary operators are used on two operands:

2 + 3
14 * 3.1415
$i – 1

These examples are also simple examples of expressions.

PHP can only perform binary operations on two operands that have the same type. However, if the two operands have different types, PHP automatically converts one of them to the other's type, according to the following rules (unless stated differently, such as in the concatenation operator).

Type of One of the OperandsType of the Other OperandConversion Performed
IntegerFloating pointThe integer operand is converted to a floating point number.
IntegerStringThe string is converted to a number. If the converted ...

Get PHP 5 Power Programming 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.