PHP Arithmetic Operators, php Arithmetic Operators
PHP Arithmetic Operators
Operator |
Name |
Description |
Instance |
Result |
X + y |
Add |
Sum of x and y |
2 + 2 |
4 |
X-y |
Subtraction |
Difference between x and y |
5-2 |
3 |
X * y |
Multiplication |
Product of x and y |
5*2 |
10 |
X/y |
Division |
Vendors of x and y |
15/5 |
3 |
X % y |
Modulo (remainder of Division) |
X divided by the remainder of y |
5% 2 10% 8 10% 2 |
1 2 0 |
-X |
Invert |
X Inversion |
-2 |
|
A. B |
Collocated |
Connect two strings |
"Hi". "Ha" |
HiHa |
The following example demonstrates different results obtained using different arithmetic operators:
<? Php $ x = 10; $ y = 6; echo ($ x + $ y); // outputs 16 echo ($ x-$ y ); // output 4 echo ($ x * $ y); // output 60 echo ($ x/$ y); // output 1.6666666666667 echo ($ x % $ y ); // output 4?>
Run
Related reading:
Php strstr checks whether a string exists in the same string.
The php stristr () function finds the first occurrence of a string in another string.
The php strchr () function finds the first appearance of a string in another string.
Usage of strncasecmp, a comparison function between two php Strings
Php strcasecmp compares two strings to determine if they are equal (compares the size of the two strings)