PHP Reading Notes operator explanation, Reading Notes operator explanation
What is an operator?
What is an operator? An operator is an identifier that tells PHP to perform related operations. For example, if you want to calculate the value equal to 123 multiplied by 456, you need a symbol to tell the server that you need to perform a multiplication operation.
What are the operators in PHP? PHP operators include Arithmetic Operators, value assignment operators, comparison operators, ternary operators, logical operators, String concatenation operators, and error control operators.
Arithmetic Operators in PHP
Arithmetic Operators are mainly used for arithmetic operations, such as addition, subtraction, multiplication, and Division operations. Common Arithmetic Operators in PHP correspond to the following table:
Value assignment operator in PHP
There are two assignment operators in PHP:
(1) "=": assigns the value of the right expression to the number of operations on the left. It copies the expression value on the right to the number of operations on the left. In other words, I first applied a piece of memory for the number of operations on the left, and then put the copied value in the memory.
(2) "&": Reference Value assignment, meaning that both variables point to the same data. It will make the two variables share a piece of memory. If the data stored in this memory changes, the values of the two variables will change.
Comparison operators in PHP
Comparison operators are mainly used for comparison operations, such as equal to, full, unequal, greater than, or less. The following table lists common comparison operators in PHP:
Ternary operators in PHP
("? : ") The ternary operator is also a comparison operator. For an expression (expr1 )? (Expr2) :( expr3). If the value of expr1 is true, the value of this expression is expr2; otherwise, it is expr3.
Logical operators in PHP
Logical operators are mainly used for logical operations, such as logical and, logical or, logical XOR, and non-logical operations. The following table lists commonly used logical operators in PHP:
We can understand logical operations from the perspective of voting:
1. Logic and:A certain agreement will be passed only when everyone is required to vote for it;
2. Logic or:Only one person is required to vote for it;
3. Logic exclusive or:Only one person can vote for it;
4. Non-logical:An individual wants to oppose it, but does not invalidate it through logic;
There are two different operators, "and" and "or", because they calculate priority (that is, the finite order of operations. For example, we learned four arithmetic operations in elementary school, the addition, subtraction, multiplication, division, and subtraction are different.
We can understand logical operations from the perspective of voting:
1. Logic and:A certain agreement will be passed only when everyone is required to vote for it;
2. Logic or:Only one person is required to vote for it;
3. Logic exclusive or:Only one person can vote for it;
4. Non-logical:An individual wants to oppose it, but does not invalidate it through logic;
String concatenation operators in PHP
The String concatenation operator is used to connect two strings. The following string Concatenation Operators are provided in PHP:
(1) concatenation operator ("."): it returns the string obtained after attaching the right parameter to the left parameter.
(2) join value assignment operator (". ="): it attaches the parameter on the right to the parameter on the left.
Error Control Operators in PHP
PHP provides an error control operator "@". For expressions that may encounter errors during running, we do not want to display error messages to customers when errors occur, this is unfriendly to users. Therefore, you can place @ before a PHP expression. Any error information that may be generated by this expression is ignored;
If track_error is activated. set in ini). Any error information generated by the expression is stored in the $ php_errormsg variable. This variable is overwritten every time an error occurs, therefore, if you want to use it, you must check it as soon as possible.
Note that the error control prefix "@" does not block parsing error information. It cannot be placed before the definition of a function or class, or be used for condition structures such as if and foreach.
The above PHP Reading Note _ Operator details are all the content shared by the editor. I hope you can give us a reference and support the help house.