Programming Tutorials

Binary Operators in PHP

By: Andi, Stig and Derick in PHP Tutorials on 2008-11-22  

Concatenation Operator (.)

The concatenation operator concatenates two strings. This operator works only on strings; thus, any non-string operand is first converted to one.

The following example would print out "The year is 2000":

$year = 2000;

print "The year is " . $year;

The integer $year is internally converted to the string "2000" before it is concatenated with the string's prefix, "The year is".

Numeric Operators All the binary operators (except for the concatenation operator) work only on numeric operands. If one or both of the operands are strings, Booleans, nulls, or resources, they are automatically converted to their numeric equivalents before the calculation is performed.

Operator Name Value
+  Addition The sum of the two operands.

The difference between the two operands.

* Multiplication

The product of the two operands.

/ Division

The quotient of the two operands.

% Modulus

Both operands are converted to integers. The result is the remainder of the division of the first operand by the second operand.

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in PHP )

Latest Articles (in PHP)