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:
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)