PHP Learning Operators and operator Precedence _php tutorial

Source: Internet
Author: User
Arithmetic operators
Operator name Result
$a + $b addition $a and $b and
$a-the difference between $b subtraction $a and $b
$a * $b multiplication $a and the product of $b
$a/$b division $a divided by the quotient of the $b
$a% $b modulo $a divided by the remainder of the $b
Increment/decrement operator
Operator name Result
+ + $a the value of the pre-add $a plus one, and then proceed
$a + + after adding a $a value to the first operation, after adding a
--$a the value of the pre-minus $a minus one and then the operation
$a--the value of the post-minus $a is first operated, minus one
Instance:
echo $a =5+ "5th"; Output: 10
Echo 10%3; Output: 1
echo + + $a + +; Output: 20
Echo 5--$a; Output: 5
?>
Comparison operators
Operator name Result
$a = = $b equals TRUE if $ A equals $b
$a = = = $b Congruent TRUE if $ A equals $b and their type is the same
$a! = $b equal to TRUE if $ A is not equal to $b
$a <> $b equal to TRUE if $ A is not equal to $b
$a!== $b non-congruent TRUE if $ A is not equal to $b, or if they are of different types
$a < $b less than TRUE if $ A is strictly less than $b
$a > $b greater than TRUE if $ A is strictly $b
$a <= $b less than or equal to TRUE if $a is less than or equal to $b
$a >= $b greater than or equal to TRUE if $a is greater than or equal to $b
Another conditional operator is "? : "(or ternary) operator.

Instance:
Var_dump (0== "a"); Output: bool (TRUE)
Var_dump (0== "00"); Output: bool (TRUE)
Var_dump (0=== "00"); Output: bool (FALSE)
Var_dump (0<> "abc"); Output: bool (FALSE)
Var_dump (0!== "01"); Output: bool (TRUE)
$a = 10;
$b = 20;
$str = $a > $b? "True": "false";
Echo $str; Output: false
?>
logical operators
Operator name Result
$a and $b logic with true if $a and $b are true.
$a or $b logical or true if either $a or $b is true.
$a XOR $b different or TRUE if $a and $b are not simultaneously
! $a logic is not true if the $a is not true.
$a && $b logic with True if $a and $b are true.
$a | | $b logical OR True if either $a or $b is true.

Where and with &&, OR and | | is a two-way notation for the same logical operator.
Logical and logical or both are short-circuit operators. When the following logical expression is encountered, the PHP interpreter will not evaluate the expression on the right:
$a = 10;
if (false && (+ + $a));
echo $a; Output: 10
$b = 10;
if (true or (+ + $b));
Echo $b; Output: 10
?>
Bitwise operators
The bitwise 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.
Expression name Result
$a & $b Bitwise is set to 1 for both the $a and the 1 bits in the $b.
$a | $b bitwise or sets the bit in the $a or the $b as 1 to 1.
$a ^ $b Bitwise XOR will set the different bits in the $a and $b to 1.
~ $a bitwise is not set to 1 for bits 0 in the $a, and vice versa.
$a << $b left shifts the bits in the $a to the left $b times (each move represents "multiplied by 2").
$a >> $b right moves the bits in the $a to the right $b times (each move represents "divided by 2").
Other operators
String operators
There are two string operators. The first one is the join operator (".") ), which returns the string after its left and right arguments are concatenated. The second is the Join assignment operator (". ="), which attaches the right argument to the left argument.
Error suppression operator
In the most common database connection and file creation operations or when exceptions such as 0 are present, you can suppress the function error message output to the browser by using the @ symbol $a =@ (5/0)
External command execution
Use ' to run External system commands, note not single quotes, is the key below ESC
$out = ' dir c: ';
Print_r ($out);
? >//is not recommended for use
Instance:
$a = "Hello";
$a. = "world! "; Equivalent to: $a = $a. "World!";
echo $a; Output: Hello world!
$m = 3;
$m + = 5; Equivalent to: $m = $m +5;
Echo $m; Output: 8

$c = ($b = 4) + 5;
Echo $c; Output: 9
?>
Operator Precedence
The following table lists the precedence of operators from low to high.
Combining direction operators
Left
Left or
Left XOR
Left and
Right print
right = + = = *=/=. =%= &= |= ^= ~= <<= >>=
Left? :
Left | |
Left &&
Combining direction operators
Left |
Left ^
Left &
No = = = = = = =!==
No < <= > >=
Left << >>
Left +-.
Left */%
Right! ~ + +--(int) (float) (string) (array) (object) @
Right
No new

http://www.bkjia.com/PHPjc/319103.html www.bkjia.com true http://www.bkjia.com/PHPjc/319103.html techarticle The arithmetic operator name results $a + $b addition of $ A and $b and $a-$b subtraction of $ A and $b $a * $b multiply $ A and $b's product $a/$b division $ A divided by $b quotient $a% $b modulo $ A to divide by $b's remainder increment/pass ...

  • Related Article

    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.