PHP operator (1) "arithmetic operator" example

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.