PHP arithmetic operators
operator |
name |
Description |
Example |
Results |
X + y |
Add |
X and Y's and |
2 + 2 |
4 |
X-y |
Reducing |
The difference between x and Y |
5-2 |
3 |
X * y |
By |
The product of X and Y |
5 * 2 |
10 |
X/Y |
Except |
Quotient of X and Y |
15/5 |
3 |
X% y |
Modulo (remainder of division) |
The remainder of x divided by Y |
5% 2 10% 8 10% 2 |
1 2 0 |
-X |
Take counter |
X inverse |
+ t |
|
A. B |
collocated |
Connect two strings |
"Hi". "Ha" |
Hiha |
The following example shows the different results obtained using different arithmetic operators:
<?php $x = 10; $y =6;echo ($x + $y); Output 16echo ($x-$y); Output 4echo ($x * $y); Output 60echo ($x/$y); Output 1.6666666666667 Echo ($x% $y); Output 4?>
Run
Related reading:
PHP strstr determine if a string exists in a string
The PHP stristr () function finds the first occurrence of a string in another string
The PHP strchr () function finds the first occurrence of a string in another string
PHP two string comparison function strncasecmp How to use a detailed
PHP strcasecmp compares two strings for equality (compares the size of two strings)
PHP arithmetic operators