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

Source: Internet
Author: User
1. Arithmetic operators

Common arithmetic operators

Type of operation Operator Example Results
Take inverse operation - -$a Returns a negative value of $ A
Addition operation + $a + $b Returns $ A with $b and
Subtraction operations - $a-$b Returns the difference between $ A and $b
Multiplication operations * $a * $b Returns the product of $ A and $b
Division operation / $a/$b Returns $ A and $b quotient
Take the remainder operation % $a% $b Returns the remainder of $ A and $b

2. Logical operators

logical operators in PHP

Type of operation Operator Example Results
Logic and && or $a && $b or $a and $b Returns True when $ A and $b are true, otherwise false
Logical OR || OR OR $a | | $b or $a or $b Returns True when $ A or $b is true, otherwise false
Logical XOR or Xor $a XOR $b When $ A true $b false or $ A fake $b true, returns True, otherwise returns false
Logical Non- ! ! $a Returns True when $ A is false, otherwise returns false

3. Assignment operators

The assignment operator "=" is the most basic operator in PHP, which assigns the value of the expression "=" to the left-hand operand.

In addition, PHP is commonly used to compound assignment operators.

Compound assignment operator

Type of operation Operator Example Results
Addition Assignment += $a + = 5 $a plus 5 and assign a value to $ A
Subtraction Assignment -= $a-= 5 $a minus 5 is assigned a value of $ A
Multiply Assign Value *= $a *= 5 $a multiplied by 5 for the product assignment to $ A
Division Assignment /= $a/= 5 The quotient of $a divided by 5 is assigned to $ A
Assignment of residual value %= $a%= 5 $a is assigned to $ A by dividing the remainder of 5

4. Comparison operators

td> returns True if the value of $a is greater than the value of $b, otherwise false
operation type operator example result
less than < $a < $b returns True if $a value is less than $b value, otherwise false
greater than ; $a > $b
is less than or equal to <= $a <= $b When the value of $a is less than or equal to Returns True if $b value, otherwise false
is greater than or equal to >= $a >= $b When the value of $a is greater than or equal to $b, the return is true, otherwise return false
equal = $a = = $b Returns True if the value of $a equals $b, otherwise returns false
congruent = = = $a = = = $b returns True if the value of the $a equals the value of the $b, and the $a is equal to the type of the $b, otherwise false
is not equal ! = $a! = $b or $a <> $b returns False if the value of the $a equals the value of $b, otherwise returns true
not identical !== $a!== $b when $a value equals $b value, and $ A is equal to the type of $b, False is returned, otherwise true

The above describes the operators in PHP---arithmetic operators, logical operators, assignment operators, comparison operators, including aspects of the content, you want to be interested in PHP tutorial friends helpful.

  • 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.