PHP operators: Arithmetic operators, logical operators, trinocular operators, bitwise operators, string operators.

Source: Internet
Author: User
Tags arithmetic operators bitwise operators

Assignment operators

The PHP assignment operator is used to write values to variables. The base assignment operator in PHP is "=".

This means that the right-hand copy expression sets the value for the left-hand operand.

___________________________________________________________________________________________________

Arithmetic character (+-*/%)

There are 4 mathematical operations symbols for arithmetic and mathematical operators, including: "+" (plus), "-" (minus) "*" (multiply), "/" (except). These are commonly familiar symbols, and the operators in PHP are basically similar, just one more "%" to find the remainder of the symbol.

_____________________________________________________________________________________________________

Logical Operators (| | &&! ^)

The logical operators in PHP are the same as, or, XOR, or not 4 types. There are two representations of logic and logic.

______________________________________________________________________________________________________

Trinocular operator for conditional expression b?x:y, the condition B is evaluated first and then judged. If the value of B is true, the value of x is computed, the result of the operation is the value of x, otherwise, the value of Y is evaluated and the result of the operation is Y. A conditional expression never evaluates both X and Y. The conditional operator is right-associative, that is, a right-to-left grouping is calculated. For example, A?b:c?d:e will be executed by a?b: (c?d:e). [1] < expression 1>?< expression 2>:< expression 3>; "?" The meaning of the operator is that the value of expression 1 is evaluated first, and if true, the expression 2 is executed and the result of expression 2 is returned; If the value of expression 1 is false, an expression of 3 is executed and the result of expression 3 is returned. Can be understood as condition? Result 1: Result 2The inside? Number is a format requirement. It can also be understood as whether the condition was established, the condition was set as result 1 otherwise for the result 2. A?b:c Simple way to understand: if (a) {return B;} Else{return C;} ________________________________________________________________________________________________________ Bitwise operators

The operator allows you to set the bits specified in the integer number. If both the left and right arguments are strings, the bitwise operator will manipulate the ASCII value of the character.

_________________________________________________________________________________________________________

String operator notation
operator name Example Results
. Thread connection $txt 1 = "Hello" $txt 2 = $txt 1. "World!" Now $txt 2 contains "Hello world!"
.= String Assignment $txt 1 = "Hello" $txt 1. = "world!" Now $txt 1 contains "Hello world!"
The following example shows the result of using the string operator: instance <?php$a = "Hello"; $b = $a. "World!"; Echo $b; Output Hello world! $x = "Hello"; $x. = "world!"; echo $x; Output Hello world!? >______________________________________________________________________________________________________ Increment/ Decrement operator symbol
operator name Description
+ + $x Pre-increment $x adds an increment, and then returns $x
$x + + Post-increment Return $x, then $x plus one increment
--$x Before descending $x decreases by one and then returns $x
$x-- After descending Return $x, then $x minus one decrement
The following example shows the different results using different increment/decrement operators: Example <?php$x=10; echo + + $x; Output 11$y=10; echo $y + +; Output 10$z=5;echo--$z; Output 4$i=5;echo $i--; Output 5?> Running instance

____________________________________________________________________________________________________

comparison operator notation the PHP comparison operator is used to compare two values (numbers or strings):
operator name Example Results
== Equals $x = = $y Returns True if the $x equals $y.
=== Congruent (exact same) $x = = = $y Returns True if $x equals $y and they are of the same type.
!= 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 are not equal to $y and they are of different types.
> Greater than $x > $y Returns True if the $x is greater than $y.
< Less 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.
<= Less than or equal to $x <= $y Returns True if $x is less than or equal to $y.
The following example shows the different results of using some comparison operators: instances <?php$x=100; $y = "Var_dump" ($x = = $y), echo "<br>", var_dump ($x = = = $y), echo "<br>"; Var_dump ($x! = $y); echo "<br> Var_dump ($x!== $y), echo "<br>", $a =50, $b =90;var_dump ($a > $b); echo "<br>"; Var_dump ($a < $b); > Running Instance __________________________________________________________________________________________________ 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 at least one of the $x and $y is true.
Xor XOR or $x XOR $y Returns True if $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 at least one of the $x and $y is true.
! Non - ! $x Returns True if the $x is not true.


_______________________________________________________________________________________________________

Array operators

equal tr>
  operator name example results
+ Union $x + $y $x and $y Union (but does not overwrite duplicate keys)
= = $x = = $y returns True if $x and $y have the same key/value pair.
= = = congruent $x = = = $y returns True if $x and $y have the same key/value pair and the same order type.
! = unequal $x! = $y Returns True if $x is not equal to $y.
<> not Equal $x <> $y Returns True if $x is not equal to $y.
!== not congruent $x!== $y Returns True if the $x is completely different from the $y.
The following example shows different results using different array operators: instance <?php$x = Array ("A" = "red", "b" = "green"); $y = Array ("c" = "Blue", "d" = "yellow"); $z = $x + $y; $x Joint var_dump with $y ($z), var_dump ($x = = $y), var_dump ($x = = = $y), var_dump ($x! = $y); Var_dump ($x <> $y); Var_dump ($x !== $y);? >

PHP operators: Arithmetic operators, logical operators, trinocular operators, bitwise operators, string operators.

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.