PHP operator (Operators)

Source: Internet
Author: User
Operators this section describes Operators in PHP ).

An operator can generate another value (thus the entire structure becomes an expression) by giving one or more values.

An operator is something that you feed with one or more values (or expressions, in programming jargon) which yields another value (so that the construction itself becomes an expression ).

Arithmetic Operators)
Operator Description Example Result
+ Add

2 + 2

$ A + $ B

4

Sum of $ a and $ B

- Subtraction

3-2

$ A-$ B

1

The difference between $ a and $ B

* Multiplication

3*2

$ A * $ B

6

The product of $ a and $ B

/ Division

3/2

$ A/$ B

1.5

Result of variable $ a divided by $ B

% Remainder

3/2

$ A % $ B

1

Variable $ a divided by the remainder of $ B

Assignment Operators)

The basic value assignment operator is =. You may think it is "equal", but it is not. It actually means assigning the value of the right expression to the number of operations on the left.

For example, $ a = 5 indicates that the value of 5 is assigned to the variable $.

In PHP, = indicates a value, and = indicates a value. = See the following comparison operators.

Comparison Operators)
Operator Description Example
= Equal 6 = 6 return TRUE
! = Not equal 7! = 8 return TRUE
< Less 8 <7 return FALSE
> Greater 8> 7 return TRUE
<= Less than or equal 8 <= 9 return TRUE
> = Greater than or equal 8> = 9 return FALSE
Logical Operators)
Operator Description Example
&& And

$ A & $ B

Returns TRUE if both $ a and $ B are TRUE.

| Or

$ A | $ B

Returns TRUE if any of $ a and $ B is TRUE.

! Not

! $

Returns TRUE if $ a is not TRUE.

Xor Xor

$ A xor $ B

If either of $ a and $ B is TRUE but not both, TRUE is returned.

Increment/decrease operator (Incrementing/Decrementing Operators)
Operator Description Example
++ Increment

$ A ++, returns $ a, and adds the value of $ a to 1.

+ $ A, add 1 to the value of $ a, and then return $

-- Decrease

$ A --, $ a is returned, and then the value of $ a is reduced by 1.

-- $ A, the value of $ a is reduced by 1, and then $ a is returned.

String Operators)

There are two character operators. One is the concatenation operator, which is used to connect two strings; the other is the concatenation assignment operator. =, which attaches the parameter on the right to the parameter on the left. Example:

Operator Example Result
. "Hello". "World" HelloWorld
. =

$ A = "Hello ";

$ A. = "World ";

$ A. = "World" is equivalent to $ a = $ a. "World"

The value of $ a is HelloWorld.

Combination of value assignment operators and arithmetic operators
Operator combination Example Description
+ = $ A + = 3 $ A = $ a + 3
-= $ A-= 3 $ A = $ a-3
* = $ A * = 3 $ A = $ a * 3
/= $ A/= 3 $ A = $ a/3
% = $ A % = 3 $ A = $ a % 3

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.