Operators in PHP --- Arithmetic Operators, logical operators, value assignment operators, comparison operators, and operator assignment

Source: Internet
Author: User

Operators in PHP --- Arithmetic Operators, logical operators, value assignment operators, comparison operators, and operator assignment

1. Arithmetic Operators

Common Arithmetic Operators

Operation Type Operator Example Result
Inverse Operation - -$ Returns a negative value of $.
Addition operation + $ A + $ B Returns the sum of $ a and $ B.
Subtraction - $ A-$ B Returns the difference between $ a and $ B.
Multiplication * $ A * $ B Returns the product of $ a and $ B.
Division / $ A/$ B Returns the quotient of $ a and $ B.
Remainder operation % $ A % $ B Returns the remainder of $ a and $ B.

2. logical operators

Logical operators in PHP

Operation Type Operator Example Result
Logic and & Or and $ A & $ B or $ a and $ B If both $ a and $ B are true, true is returned. Otherwise, false is returned.
Logic or | Or $ A | $ B or $ a or $ B If $ a or $ B is true, true is returned. Otherwise, false is returned.
Logic exclusive or Xor $ A xor $ B If $ a is true, $ B is false, or $ a is false, $ B is true. Otherwise, false is returned.
Non-logical ! ! $ Returns true if $ a is false; otherwise, false.

 

3. Value assignment operator

The value assignment operator "=" is the most basic operator in PHP. That is, the value of the right expression "=" is assigned to the number of operations on the left.

In addition, compound assignment operators are also commonly used in PHP.

Compound assignment operator

Operation Type Operator Example Result
Addition assignment + = $ A + = 5 $ A and the sum of 5 are assigned to $.
Subtraction assignment -= $ A-= 5 $ A minus 5 is assigned to $.
Multiplication assignment * = $ A * = 5 $ A multiplied by the product of 5 and assigned to $
Division assignment /= $ A/= 5 $ A is assigned to $ a by the operator of 5.
Remainder assignment % = $ A % = 5 $ A is assigned to $ a by the remainder of 5.

4. Comparison Operators

 

Operation Type Operator Example Result
Less < $ A <$ B If the value of $ a is less than the value of $ B, true is returned. Otherwise, false is returned.
Greater > $ A> $ B If the value of $ a is greater than the value of $ B, true is returned. Otherwise, false is returned.
Less than or equal <= $ A <= $ B If the value of $ a is less than or equal to the value of $ B, true is returned. Otherwise, false is returned.
Greater than or equal > = $ A> = $ B If the value of $ a is greater than or equal to the value of $ B, true is returned. Otherwise, false is returned.
Equal = $ A = $ B If the value of $ a is equal to the value of $ B, true is returned. Otherwise, false is returned.
Full === $ A ===$ B If the value of $ a is equal to the value of $ B and $ a is of the same type as $ B, true is returned. Otherwise, false is returned.
Not equal ! = $! = $ B or $ a <> $ B If the value of $ a is equal to the value of $ B, false is returned. Otherwise, true is returned.
Incomplete ! = $! ==$ B If $ a is equal to the value of $ B and $ a is of the same type as $ B, false is returned. Otherwise, true is returned.

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.