2.1 KiB
2.1 KiB
title |
---|
PHP Operators |
PHP Operators
Operators are used to perform operations on variables and values.
PHP divides the operators in the following groups:
- Arithmetic operators
- Assignment operators
- Comparison operators
- Increment/Decrement operators
- Logical operators
- String operators
- Array operators
PHP Arithmetic Operators
The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.
Operator | Name | Example | Result |
---|---|---|---|
+ | Addition | $a + $b | Sum of $a and $b |
- | Subtraction | $a - $b | Difference of $a and $b |
* | Multiplication | $a * $b | Product of $a and $b |
/ | Division | $a / $b | Quotient of $a and $b |
% | Modulus | $a % $b | Remainder of $a divided by $b |
** | Exponentiation | $a ** $b | Result of raising $a to the $b'th power |
PHP Assignment Operators
The assignment operator is =
. The operand on the left side gets assigned the value of the expression on the right.
Example
<?php
$a = 7; // $a set to 7.
?>