An operator is a symbol used to calculate variables, constants, or data. it is a specified operation performed on a value or a group of values. PHP operator: arithmetic operator, string operator, value assignment operator, bit operator, logical operator, comparison operator, increment or decrease operator, error control operator. Next, we will explain the arithmetic operators in PHP operators.
What is a php arithmetic operator?
IntroductionArithmetic operatorsBefore that, let's take a look at what is an operator. an operator is a symbol used to perform code operations on variables, constants, or data, it is a specified operation on a value or a group of values. PHP operator: arithmetic operator, string operator, value assignment operator, bit operator, logical operator, comparison operator, increment or decrease operator, error control operator. Next, we will explain the arithmetic operators in PHP operators.
Introduction to various symbols of arithmetic operators:
Arithmetic operators are symbols used to process arithmetic operations. The most commonly used arithmetic operators are listed below.
| Operator |
Description |
Example |
| + |
Addition operation |
$ A + $ B |
| - |
Subtraction |
$ A-$ B |
| * |
Multiplication |
$ A * $ B |
| / |
Division |
$ A/$ B |
| % |
Remainder operation |
$ A % $ B |
| ++ |
Incremental operation |
$ A ++, ++ $ |
| -- |
Descending operation |
$ A --, -- $ |
PS: % is used to calculate the remainder in arithmetic operators. if the divisor ($ a) is a negative number, the result is also a negative value.
Here we will talk about the last two increment/decrease operators, mainly to operate on a single variable.
The increment/decrease operator can be used in either of the following ways:
First, increase or decrease the variable by 1, and then assign the value to the original variable, which is called the pre-increment/decrease operator.
Second, place the operator behind the variable, first return the current value of the variable, and then increase or decrease the current value of the variable by one. We call it the post-increment/decrease operator.
Arithmetic operator usage example
The following example uses several operators in the preceding table for calculation. the code is as follows:
\n";echo $a-$b."
\n";echo $a*$b."
\n";echo $a/$b."
\n";echo $a%$c."
\n";$a++;echo $a."
\n";++$a;echo $a."
\n";$c--;echo $c;?>
The running result is as follows:
The preceding example is a simple application of arithmetic operators. For more information, seePhp operator topic. The next section describes the concepts and usage of string operators in detail.
Recommended video tutorials:
Php1.cn solitary 9 base (4)-php Video Tutorial: Operator (1): arithmetic operators, string operators, and value assignment operators
The above is the details of the PHP operator (1) "arithmetic operator" example. For more information, see other related articles in the first PHP community!