: This article mainly introduces PHP beginners. if you are interested in the PHP Tutorial, refer to it. PHP beginners operator
Computation results
I. arithmetic operators
1. +-*/; corresponds to addition, subtraction, multiplication, and division in mathematics. similar to $ a = $ B + $ c, it is not affected by the value type during division.
2, %; perform remainder, modulo; the remainder is 5% 3, and the final result is 2. after division, the value that does not move is the remainder.
During the modulo operation, the positive and negative results of the operation depend on the divisor symbol.
2. Comparison operators;> greater, <小于,> = Greater than or equal to, <= less than or equal ,! = Not equal to, = equal to, === all equal to (not only the values are equal, but also the data types ),! = Not all equal
3. string operators; only one function is available. concatenate strings in the form. Point,
4. value assignment operator; = assign the value = to the variable on the left.
5. logical operators;
1. logic or | or, one of several conditions can be true.
2. logic and & OR and must be established in several conditions.
3. priority of logical operations; & priority ratio | high
6. logic inversion ;! When making logical judgment, add !, Indicates making a judgment on the logic of the parameter to be judged.
VII. exclusive or operation. the xor condition must be true or false.
8. ternary operators; conditions? Return value 1: return value 2; if the condition is true, return value 1. if the condition is false, return value 2, which is similar to if {} else {}
9. increment/decrease operator; + + + 1, -- When subtraction 1 is on the left side of the variable, it is first used for calculation and then for calculation on the right side of the variable.
10. bitwise operations; binary + logical operations
For example, 5 = 4 + 1
= 1*4 + 0*2 + 1*1
= 1*2 ^ 2 + 0*2 ^ 1 + 1*2 ^ 0
= 101 (2)
0/1 is used in the computer to store information. A unit that can store 0/1 is called bit. eight digits constitute one byte. the byte is the most basic unit in the computer. when the binary value of 5 occupies only three digits, in order for the computer to understand, the input format is 0000 0101, that is, the difference is filled with 0
In other words, 0/1 is a stroke in a Chinese character. in a computer, 8 strokes are required for a Chinese character, but some Chinese characters are written after 3 strokes, in this case, a fixed stroke is needed for filling,
& (And); alignment of two binary values. consider 1 as true and 0 as false. perform the parallel operation on each bit, for example;
12 = 0000 1100
5 = 0000 0101
12 & 5 = 0000 0100 = 4
| (Or); alignment of the two binary values. consider 1 as true and 0 as false. perform or operations on each bit, for example;
12 = 0000 1100
5 = 0000 0101
12 | 5 = 0000 1101 = 13
^ (Exclusive or); alignment two binary values, regard 1 as true, regard 0 as false, and perform an exclusive or operation on each bit, for example;
12 = 0000 1100
5 = 0000 0101
12 | 5 = 0000 1001 = 9
~ (Inverse); there is a binary value. 1 is regarded as true, 0 is regarded as false, and an inverse operation is performed on each bit, for example;
12 = 0000 1100
~ 12 = 1111 0011 =-13
Note: the complement rules,
1. in binary, the highest bit indicates positive and negative, 0 indicates positive, and 1 indicates negative. for example, the first digit of 1111 is the sign bit, that is, the positive and negative signs.
2. absolute values of the remaining seven digits. For example, () 111 0011 = 115
3. subtract the absolute value 2 ^ 7. for example, 115-128 =-13.
4. 1000 0000 = "-128
1111 1111 = "-1
0000 0000 = 0
0111 1111 = 127
11. shift operation;
<; An eight-digit binary value, which is removed from the left and added (0) from the right to generate a new value.
For example, 5 = 0000 0101
5 <1 = 0000 1010 = 10, remove one digit from the left, and add one digit from the right (0)
>>; An eight-bit binary value is removed to the right. (0) is added from the left to generate a new value.
For example, 5 = 0000 0101
5> 1 = 0000 0010 = 2, remove one digit from the right, and add one digit from the left (0)
The above introduces the PHP beginner's operators, including some content, and hopes to help those who are interested in the PHP Tutorial.