Simple learning of PHP
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,
"-", sign
will subtract two variables of the same type
The "*" sign
multiplies two variables of the same type
"%" take the remainder to
divide two variables, take the remainder
"/" division sign Divide
two numbers
++ 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
The use method of-symbol and ++ symbol is similar, but-symbol is self-decreasing
The string link operator
symbol form is **.**
You can also paste the string directly
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
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
equal, and output 1 when they are equal, and no output
2 when they are not equal .= (Congruent) (value and type must be equal)
**=versus**The difference is in the picture above
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.
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)
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.
Can refer to mathematics or, and, not
- (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
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
. 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
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
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
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
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
. The role of
brackets : the things inside the brackets will be regarded as a whole.
Short circuit problem
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