PHP simple learning operators

Simple operator

Definition : A symbol that performs a certain operation on one or more variables or values, also called an operator.
There are many kinds of operators in PHP language. I only record +, —, *, /, %, ++, — —, seven kinds this time.
This operator is very similar to the C language operator.
"+", sign
will add two variables of the same type,
as shown in the figure below,
Insert picture description here
"-", sign
will subtract two variables of the same type
Insert picture description here

The "*" sign
multiplies two variables of the same type

Insert picture description here
"%" take the remainder to
divide two variables, take the remainder
Insert picture description here
"/" division sign Divide
two numbers Insert picture description here
++ sign
++ sign is divided into front ++ and after ++ , ++ sign
can be regarded as output first and then self increase

++$a;=$a=$a+1和echo $a
$a++;=echo $a;和$a=$a+1

Insert picture description here
The use method of-symbol and ++ symbol is similar, but-symbol is self-decreasing

The string link operator
symbol form is **.**

Insert picture description here
You can also paste the string directly

Insert picture description here

Assignment operator

Note ; the assignment operator has a value, so the entire statement is an expression, so you can also write
a = a=a= b=2;
Form:=,+=, -=, *=, /= %=, .=
assigns the valueon theright to the value on the left.
For example, by
Insert picture description here
analogy, the double assignment operator operates in the same way

Comparison operator

(PHP stipulates that when outputting the bool type, ture is 1, and flase does not output anything)
So when we need to output the value of the bool type, we can use the var_dump() function
to compare the operands according to the rules of this comparison operator
If the result of the comparison meets the requirements of the comparison operator, then the result is true otherwise it is false
1.Compare whether the two values ​​are
Insert picture description here
equal, and output 1 when they are equal, and no output
2 when they are not equal .
=
(Congruent) (value and type must be equal)
Insert picture description here
**=versus**The difference is in the picture above

Insert picture description here
Insert picture description here
As can be seen from the above figure, the type and value must be the same to be congruent with
3.**! =**Not equal
If the two values ​​are not equal, the output ture is equal and false
is output and not for the type, only for the value.

Insert picture description here
4. **<>= also means not equal, ibid.
5.
! == insufficiency, etc.
If the two numbers are congruent output flase (meaning nothing output)
If the two numbers congruent output ture (output 1)
Insert picture description here
1.6.
<, <=,>,> = ** these operators, we are more familiar, not one record
if the conditions operator, the output ture, does not meet the false output

Logical Operators

The result of this operator and the comparison operator is the same. If it meets the requirements, it is ture. If it does not meet the requirements, it is false
. The value that can be counted in the logic must be a bool type value. If not, it will be automatically converted by the PHP language.
Insert picture description here

Can refer to mathematics or, and, not

  1. (Logical AND operator) When the value of the expression on the left
    and
    right sides of the form and or && is true, the result of the operation is true.
    As long as there is a false, the result obtained is false
    Insert picture description here
    2. (Logical OR operator) The
    form or or ||
    As long as one of the expressions on the left and right sides is futile, the result of the operation is true. Only when the values ​​on both sides are false, the result is false
    Insert picture description here
    . 3. (Logical exclusive OR)
    form:
    the values ​​on the left and right sides of xor are not When the same, the result is true, if the same, then the result is false
    4. (Logical negation)
    form **!**
    negates the value of the original expression

Insert picture description here

Bit operator (very few used, no record)

It is used to perform operations on each secondary system position in the operand. Since PHP is mainly used for website development, bit operations are used less (yes, here is the number of words in the water)

Other operators

1. (?:)
Ternary operator
Format:
expression 1? Expression 2: Expression 3;
Meaning:
If the value of expression 1 is true, then execute expression 2, otherwise execute expression 3
Insert picture description here
Insert picture description here
as shown in the figure above
2. ( `` )
You can put system commands inside to execute , But it is rarely used, so do not record too much.
3. ( @ )
Mask the possible errors of
the expression and put it in front of the expression

Insert picture description here
4. ( =>,->, instanceot )
requires array knowledge and object-oriented knowledge, but too many records

Operator precedence

Some simple precedence operators.
The concept
of precedence ; whoever has the highest priority will be counted first.
Combination direction;
stipulate that the
Insert picture description here
higher the priority is from left to right or from right to left, the higher the priority, and the right is from right to left. , The left is counted from left to right, nothing is how to count how to count
Insert picture description here
. The role of
brackets : the things inside the brackets will be regarded as a whole.
Short circuit problem

Insert picture description here
When performing a logical operation, if the result can be determined by observing the first half, then the second half will not be calculated.
As shown in the figure above,
when a is false, it has been determined that a is false, and it can be determined.a is F a L S E , has been through may be to judge break out a && +B, then + + b, then ++b , that it+The operation of + b will not be calculated.
Similarly, or, not, are both

Guess you like

Origin blog.csdn.net/qq_51954912/article/details/114013783