PHP reading notes (4)-Operators, PHP reading note operators _php tutorials

Source: Internet
Author: User

PHP reading notes (4)-Operators, PHP reading notes operators


What is an operator

  What is an operator? The operator is an identifying symbol that tells PHP to do the related operations. For example, you need to calculate how much 123 times 456 equals, then you need a symbol to tell the server that you need to do the multiplication.

What are the operators in PHP? PHP operators are generally divided into arithmetic operators, assignment operators, comparison operators, ternary operators, logical operators, string join operators, error control operators.

Arithmetic Operators in PHP

  Arithmetic operators are primarily used for arithmetic operations, such as addition, subtraction, multiplication, and division. The usual arithmetic operators in PHP correspond to the following table:

Assignment operators in PHP

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

(1) "=": assigns the value of the right expression to the left operand. It copies the value of the right expression to the left-hand operand. In other words, the left operand is first requested for a piece of memory, and then the copied value is placed in 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 memory stored data 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 table:

  

Ternary operators in PHP

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

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

logical operators in PHP

  Logical operators are used for logical operations such as logic and logic, logical XOR, logical negation, and logical operators commonly used in PHP, such as the following table:

  We can understand the logical operation from the perspective of voting:

1, logic and: require everyone to vote for consent, will pass an agreement;

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

3. Logical XOR: only one person can vote for consent;

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

"and" and "or" have two different form operators because of the precedence of their operations (that is, the finite order of operations, such as learning arithmetic in primary school, subtraction mixing together, prioritizing multiplication, and then calculating plus and minus).

We can understand the logical operation from the perspective of voting:

1, logic and: require everyone to vote for consent, will pass an agreement;

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

3. Logical XOR: only one person can vote for consent;

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

String join operators in PHP

  The string join operator is to concatenate two strings, and the string join operators provided in PHP are:

(1) Join operator (".") : It returns the string that is appended to the right argument after the left argument.

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

Error control operators in PHP

  An error control operator "@" is provided in PHP, and we do not want an error message to be displayed to the customer when there are some expressions that may be wrong during the run, which is unfriendly to the user. Therefore, you can put the @ before a PHP expression, any error message that the expression may produce is ignored;

If the Track_error (which is set in php.ini) is activated, any error message generated by the expression is stored in the variable $php_errormsg, which is overwritten every time an error occurs, so you must check it as early as possible if you want to use it.

It is important to note that the error control prefix "@" does not mask the parsing of the error information, it cannot be placed before the definition of a function or class, nor can it be used for conditional structures such as if and foreach.

Previous article: PHP Reading notes (3)-Constants

Next article: php Reading notes (5)-Structure statements

"and" and "or" have two different form operators because of the precedence of their operations (that is, the finite order of operations, such as learning arithmetic in primary school, subtraction mixing together, prioritizing multiplication, and then calculating plus and minus).

http://www.bkjia.com/PHPjc/1138820.html www.bkjia.com true http://www.bkjia.com/PHPjc/1138820.html techarticle PHP Reading notes (4)-operator, PHP read note operator what is an operator and what is an operator? The operator is an identifying symbol that tells PHP to do the related operations. For example, you need to calculate ...

  • Related Article

    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.