1:56 AM
Arithmetic Operators
posted under
by FR3@K
|
Edit This
Arithmetic Operators in Php are just like the ones you use in mathematics.
+ addition $x + $y
- subtraction $x - $y
* multiplication $x * $y
/ division $x / $y
% modulus $x % $y
These operators are binary (they take two operands) but the subtraction (-) operator is also unary when used with negative numbers. The modulus operator returns the remainder of dividing its operands.
$mod_result=18 % 4;
This statement has the value 2 as a result. If you try to use arithmetic operators with strings php will try to convert the strings to numbers starting from the first character. If there are no digits at the beginning of the string the value of it will be zero.
+ addition $x + $y
- subtraction $x - $y
* multiplication $x * $y
/ division $x / $y
% modulus $x % $y
These operators are binary (they take two operands) but the subtraction (-) operator is also unary when used with negative numbers. The modulus operator returns the remainder of dividing its operands.
$mod_result=18 % 4;
This statement has the value 2 as a result. If you try to use arithmetic operators with strings php will try to convert the strings to numbers starting from the first character. If there are no digits at the beginning of the string the value of it will be zero.
Comment Form under post in blogger/blogspot