Addition¶
PHP additions apply to two different types: numbers and arrays.
For numbers, int and float, this is the classic mathematical addition.
For arrays, this is a special version of array merge: the arrays are merged, and keys are kept once they are written. This features only exists for addition and arrays. Substraction is not available.
With boolean, addition first cast the boolean to an integer, 0 or 1, and then, operates as a math addition.
With string, addition first try to convert the string to a numeric value. If it succeed, it operates as a math addition. Otherwise, it emits a type error.
With objects or resources, a type error is emitted.
<?php
$a = 1 + 2.3; // 3.3
$a2 = 1 + -2.3; // -1.3
$b = [1] + [3, 4]; // [1, 4]
?>
See also Array operators and Combining arrays using + versus array_merge in PHP.
Related : Array, integer, Floating Point Numbers, TypeError, Division, Operand, Plus +, Single