PHP Reading Notes _ operator detailed _php example

Source: Internet
Author: User
Tags arithmetic arithmetic operators logical operators

What is an operator

What is an operator? Operators are identifiers that tell PHP to do related operations. For example, you need to calculate 123 times 456 equals how much, this time you need a symbol, tell the server, you need to do multiplication.

What are the operators in PHP? PHP operators are generally divided into arithmetic operators, 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 operations, subtraction operations, multiplication operations, Division operations. The common arithmetic operators in PHP correspond to the following table:

Assignment operators in PHP

 There are two types of assignment operators in PHP, namely:

(1) "=": assigns the value of the right expression to the left-hand operand. It copies the right-hand expression value to the left-hand side of the op. In other words, first apply a piece of memory to the left-hand operand, and then put the copied value into this memory.

(2) "&": Reference assignment means that both variables point to the same data. It will allow two variables to share a piece of memory, and if the data for that memory store changes, then the values of the two variables will change.

comparison operators in PHP

Comparison operators are mainly used for comparison operations, such as: equals, congruent, unequal, greater than, less than. The comparison operators commonly used in PHP are the following tables:

Ternary operators in PHP

("?:") The ternary operator is also a comparison operator, for an expression (EXPR1)? (EXPR2):(expr3), if Expr1 value is true, the value of this expression is expr2, otherwise EXPR3.

logical operators in PHP

Logical operators are used for logical operations, such as logical and, logical, or logical XOR, logical, and so on, and the logical operators commonly used in PHP are the following tables:

We can understand logical operations from a polling point of view:

1, logic and: require all people to vote to agree, will pass an agreement;

2, logic or: only one person to vote to agree on the line;

3, the logic is different or: can only have and only one person to vote to agree;

4, logic is not: a person to oppose, but through the logic is not, so that its objection is invalid;

The reason why "and" and "or" has two different forms of operators is the precedence of their operations (that is, the finite order of operations, for example, when we were in primary school, we learned arithmetic, subtraction mixed together, the priority of multiplication and division, the calculation of addition and subtraction) is different.

We can understand logical operations from a polling point of view:

1, logic and: require all people to vote to agree, will pass an agreement;

2, logic or: only one person to vote to agree on the line;

3, the logic is different or: can only have and only one person to vote to agree;

4, logic is not: a person to oppose, but through the logic is not, so that its objection is invalid;

string concatenation operators in PHP

The string concatenation operator is designed to connect two strings, and the string concatenation operators provided in PHP are:

(1) The connection operator (".") : It returns the string that is the result of attaching the right parameter to the left argument.

(2) The Connection assignment operator (". ="): It attaches the right argument to the left parameter.

Error control operators in PHP

The error-Control operator "@" is provided in PHP, and for some expressions that may be wrong during the run, we do not want to display an error message to the customer when the error occurs, which is unfriendly to the user. You can then place the @ in a PHP expression, and any error messages that the expression may produce are ignored;

If you activate the Track_error (which is set in php.ini), any error message from the expression is stored in the variable $php_errormsg, which is overwritten every time it goes wrong, so you must check it as soon as possible if you want to use it.

It should be noted that the error control prefix "@" does not mask the information that resolves the error, nor can it be placed before the definition of a function or class, nor can it be used in conditional structures such as if and foreach.

The above PHP reading notes _ operator details are small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.