Operators in PHP --- arithmetic operators, logical operators, value assignment operators, and comparison operators

Source: Internet
Author: User
: Operators in PHP --- arithmetic operators, logical operators, value assignment operators, and comparison operators: 1. arithmetic operators common arithmetic operators calculation type operators example result calculation inverse operations -- $ a returns the negative value addition operation of $ a + $ B returns the sum of $ a and $ B subtraction operation-$ a-$ B returns the difference multiplication operation between $ a and $ B * $ a * $ B returns the product division operation between $ a and $ B $ a 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.

The above describes the operators in PHP-arithmetic operators, logical operators, value assignment operators, and comparison operators, including some content. I hope to help those who are interested in the PHP Tutorial.

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.