##$a>=$b |
##
Note: Identity means that only if the operands on both sides are equal and the data types are also equivalent, true will be returned;
For example: 0= = "0" This returns is true because the operands are equal
0== ="0" This returns false because the data types are different
4, Logical operators
Operator |
Usage |
How to use |
Instructions |
! |
##non |
##!$b
|
If $b is false, returns true;Otherwise the opposite
|
##&&
## with |
##$a&&$b |
##if$a | and $b are both true, then the result is true; otherwise false##|| |
or |
##$a||$b
| ##if Either one of $a and $b |
is true or both are true## When #, the result is true; otherwise, it is false##and ##与 |
$a and $b |
## is the same as && , but its | priority is lower
|
##or##or |
$a or $b
| is the same as || , but its priority is higher Low
|
Operator"and"和"or" is better than &&and || has a lower priority.
5. Ternary operator
Condition ? value if true : value if false
Example: ($grade>=50 ? "Passed " : "Failed")
6. Error suppression operator:
$a=@(57/0);
The divisor cannot be 0 will cause an error, so add @ to avoid error warnings.
7. Array Operator
##Operator |
How to use |
How to use |
Instructions |
##+
| ##United
| !$b
| Returns a message containing $a and $ Array of all elements in b
|
##= =
Equivalent |
##$a&&$b |
##If $a | and
$b have the same elements, return true = = = |
##hengheng |
$a||$b |
##If $a and
| $b With the same elements and the same order, return true##!=
|
Non-equivalent
##$a and $b |
If | $a and $b | are not equivalent, return
true#<> ##Not equivalent |
|
If $a and
| $b is not equivalent, returns | true
|
!= = |
##non-identity |
$a or $b |
if $a and $b is not identical, returns true |
Priority and associativity of operators:
Generally speaking, operators have a set of priorities, which is the order in which they are executed.
Operators are also associative, that is, the execution order of operators with the same priority. This order is usually left to right, right to left or irrelevant.
The table of operator precedence is given below. The top operator has the lowest priority, and the priority increases from top to bottom in the table.
Operator precedence
Associativity |
Operator |
##left |
, |
left |
##Or
|
left
|
Xor
|
left
|
And
|
right
| ##Print
|
##left
##= += -= *= /= .= %= &= |= ^= ~= <<= >>= |
| Left
? : |
| Left
|| |
##left |
&& |
left |
##| |
left |
^ |
Left |
& |
Not relevant |
##= = != = = = = != =
|
Irrelevant |
#<<= >>=
|
left |
##<< >>
|
left
|
+ - .
|
Left
|
* / %
|
right
|
! ~ ++ -- (int)(double)(string)(array)(object) @
|
right
|
[] |
Not relevant |
##New |
irrelevant |
() |
In order to avoid priority confusion, you can use parentheses to avoid priority.
|
|