PHP operator detailed

Source: Internet
Author: User
Tags arithmetic arithmetic operators bitwise bitwise operators logical operators modulus php operator

PHP arithmetic operator

operator name Example Results
+ Addition $x + $y $x and $y summation
- Subtraction $x-$y The difference between $x and $y
* Multiplication $x * $y The product of $x and $y
/ Division $x/$y Quotient of $x and $y
% Modulus $x% $y $x remainder in addition to $y

PHP increment/decrement operator

operator name Description
+ + $x Forward increments $x add one increment and then return to $x
$x + + After increment Returns $x, then $x add an increment
--$x Before descending $x decrease and then return to $x
$x-- After descending Return $x, then $x decrement

PHP assignment operator

The PHP assignment operator is used to write values to variables.

The base assignment operator in PHP is "=". This means that the right assignment expression sets the value for the left-hand operand.

Assigning values equal to Description
x = y x = y The right expression sets the value for the left operand.
X + y x = x + y Add
x = y x = XY Reducing
X *= y x = x * y By
X/= y x = x/y Except
X%= y x = x% y Modulus

PHP comparison operator

The PHP comparison operator is used to compare two values (numbers or strings):

operator name example result
= equals $x = = $y Returns True if the $x equals $y.
= = Strict (exact) $x = = $y returns True if $x equals $y and they are of the same type.
!= is not equal to $x!= $y Returns True if $x is not equal to $y.
<> not equal to $x <> $y Returns True if $x is not equal to $y.
!== not congruent (completely different) $x!== $y Returns True if $x is not equal to $y and their types are not the same 。
greater than $x > $y returns True if the $x is greater than $y.
: greater than $x < $y returns True if the $x is less than $y.
>= greater than or equal to $x >= $y Returns True if $x is greater than or equal to $y.

PHP logical Operators
operator name Example Results
and And $x and $y Returns True if both the $x and the $y are true.
Or Or $x or $y Returns true if the $x and $y at least one is true.
Xor XOR or $x XOR $y Returns true if the $x and $y have and only one is true.
&& And $x && $y Returns True if both the $x and the $y are true.
|| Or $x | | $y Returns true if the $x and $y at least one is true.
! Non - ! $x Returns True if the $x is not true.

The following table lists the operators from high to low in order of precedence. Operators in the same row have the same precedence, at which point their binding direction determines the order of evaluation.

Operator Precedence
Combining Direction operator Additional Information
None clone new clone  and  new
left [ /td> Array ()
Right + +--~ (int) (float) (string) (array) (object) (bool) @ type and increment/decrement
no instanceof type
right ! logical Operators
left */% arithmetic operator
left +-. arithmetic operators and string operators
left << >> bitwise operator
none = =!= = =!== <&G t; comparison operators
left bitwise operators and references
left ^ bitwise operators
left |

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.