PHP MYSQL - Operators - 5.1
Operators
The Operator exhibits an operation
$z = $x + $y
here =, + are operators
PHP divides the operators like
- Arithmetic operators
- Assignment operators
- Comparison operators
- Increment/Decrement operators
- Logical operators
- String operators
- Array operators
- Conditional assignment operators
PHP Arithmetic Operators
Operator | Name | Example | Result | |
---|---|---|---|---|
+ | Addition | $x + $y | Sum of $x and $y | |
- | Subtraction | $x - $y | Difference of $x and $y | |
* | Multiplication | $x * $y | Product of $x and $y | |
/ | Division | $x / $y | Quotient of $x and $y | |
% | Modulus | $x % $y | Remainder of $x divided by $y | |
** | Exponentiation | $x ** $y | Result of raising $x to the $y'th power |
Ex: +
<!DOCTYPE html>
<html>
<body>
<?php
$x = 10;
$y = 6;
echo $x + $y;
?>
</body>
</html>
<html>
<body>
<?php
$x = 10;
$y = 6;
echo $x + $y;
?>
</body>
</html>
Ex: -
<!DOCTYPE html>
<html>
<body>
<?php
$x = 10;
$y = 6;
echo $x - $y;
?>
</body>
</html>
<html>
<body>
<?php
$x = 10;
$y = 6;
echo $x - $y;
?>
</body>
</html>
Ex: *
<!DOCTYPE html>
<html>
<body>
<?php
$x = 10;
$y = 6;
echo $x * $y;
?>
</body>
</html>
<html>
<body>
<?php
$x = 10;
$y = 6;
echo $x * $y;
?>
</body>
</html>
Ex: /
<!DOCTYPE html>
<html>
<body>
<?php
$x = 10;
$y = 6;
echo $x / $y;
?>
</body>
</html>
<html>
<body>
<?php
$x = 10;
$y = 6;
echo $x / $y;
?>
</body>
</html>
Ex: %
<!DOCTYPE html>
<html>
<body>
<?php
$x = 10;
$y = 6;
echo $x % $y;
?>
</body>
</html>
<html>
<body>
<?php
$x = 10;
$y = 6;
echo $x % $y;
?>
</body>
</html>
Ex: **
<!DOCTYPE html>
<html>
<body>
<?php
$x = 10;
$y = 3;
echo $x ** $y;
?>
</body>
</html>
<html>
<body>
<?php
$x = 10;
$y = 3;
echo $x ** $y;
?>
</body>
</html>