A symbol can be used to process numbers, strings, and other conditions that require computation. The operator numbers in php are similar to those in C. for experienced programmers, they should be able to smoothly grasp the operator numbers in php.
Operator Number
Operator numbers can be used to process numbers, strings, and other conditions that require computation. The operator numbers in php are similar to those in c. for experienced programmers, they should be able to smoothly grasp the operator numbers in php.
Different operators are prioritized, just as when I was a child in mathematics, the teacher would teach: First multiplication, division, and then addition and subtraction. For the php operation priority, refer to the following table. in the case of hybrid expressions, the higher the priority, the higher the performance.
Left to right or left to right xor left to right and left to right? : Left to right | left to right & left to right | left to right ^ Left to Right & Left to right =! = Unlimited <<=>=> unlimited <> left to right-. left to right */% left to right! ~ -- @ Union rules of operators from right to left [] to right to left
As Xianzhe said? : If a thing has its end, its end, and its order of knowledge, it is nearly the same. during computation, as long as the program is written in the order of computing priority, there should be no different results than expected. Pay attention to the details when writing, which can reduce the pain points of debugging!
Logical operation
Logical operations (logical operators) are usually used to test true values. The most common logical operation is loop processing, which is used to determine whether to exit the loop or continue to execute the instructions in the loop.
<小于> Greater than <= less than or is> = greater than or equal to = is! = Not that is & and (and) | or (or) xor different or (xor )! No (not)
$ A = 5;
If ($! = 5 ){
Echo '$ a is not 5 ';
} Else {
Echo '$ a is 5 ';
}
?>
PHP bit operations
There are six bitwise operators in php, which provide numbers for fast and low-level operations. For more information about bit operations, see discrete mathematics.
& And (and) | or (or) ^ exclusive or (xor) < <向左移位> > Shift to the right ~ Meaning of the complement sign of 1
Value assignment
Assignment operator is sometimes confusing, but it can simplify the program and increase the performance efficiency of the program.
= Connect the right value to the left = add the right value to the left-= reduce the right value to the left * = multiply the left value by the right/= divide the left value by the right % = returns the remainder of the left value pair to the right. = add the string on the right to the left
$ A = 5;
$ A = 2; // $ a = $ a 2;
Echo $ .'
\ N ';
$ B = 'Wha ';
$ B. = 'har'; // $ B = 'ouar ';
$ B. = 'ha'; // $ B = 'wow Ha ';
Echo '$ B
\ N ';
?>
String operators
The string operator has only one operator number, which is an English period .. It can be used to connect strings and convert them into new merged strings.
The following is an example of string operations.
$ A = 'php 4 ';
$ B = 'powerful power ';
Echo $ a. ':'. $ B;
?>
Arithmetic operations
The arithmetic operators symbol is used to process the four arithmetic operations. it is the simplest and most commonly used symbol. in particular, the processing of numbers almost applies to arithmetic operators.
Addition operation-subtraction operation * multiplication operation/division operation % accumulate remainder -- meaning of decreasing symbol
The following is a simple arithmetic operation model
$ A = 8;
$ B = 2;
$ C = 3;
Echo $ a $ B .'
\ N ';
Echo $ a-$ B .'
\ N ';
Echo $ a * $ B .'
\ N ';
Echo $ a/$ B .'
\ N ';
Echo $ a % $ c .'
\ N ';
$;
Echo $ .'
\ N ';
$ C --;
Echo $ c;
?>
Other operators
In addition to the preceding operator numbers, some operators are difficult to return to the class.
$ Variable
& Variable address (before the variable)
@ Do not display the error message (before the function )-
> Class methods or attributes
=> Array element value
? : Ternary operator
Which of the following operations is more special? .
(Expr1 )? (Expr2): (expr3 );
If the calculation result of expr1 is true, expr2 is performed; otherwise, expr3 is performed. In fact, it is somewhat like loop with if... else, but it can make the program simpler and more efficient.