Operators are used to performing operations on variables and values.
PHP divides the operators into the following groups:
This chapter shows the different operators that can be used in PHP scripts.
The example below shows the different results of using the different 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 (Introduced in PHP 5.6) |
<?php
$x=8;
$y=4;
echo ($x + $y); // outputs 12
echo ($x - $y); // outputs 4
echo ($x * $y); // outputs 32
echo ($x / $y); // outputs 2
echo ($x % $y); // outputs 2
?>
© 2024 Easy To Learning. All Rights Reserved | Design by Easy To Learning