Basic knowledge of PHP learning day5--operators

Source: Internet
Author: User
Tags arithmetic operators bitwise operators

yesterday we learned about constants and data types related knowledge, because the previous knowledge is to be relatively simple, so some small details to learn to pay attention to, always remind yourself to be careful.

Today the main learning is operator and process control, the content is relatively simple, but also learn to pay attention to the details.

a , common operators in PHP

  The operator in PHP is basically the same as JS, and it works the same way.

  1. Arithmetic operators

In normal operations, we often use arithmetic operators, which can be used to perform simple numeric operations on data, which are called arithmetic operators.

Arithmetic operator: +,-,*,/,%,++,--

  These operations have certain data types that can be converted invisibly:

$i ="1"+"1";//2$i ="1"+1;//2$i ="1a"+1;//2$i ="1abd"+1;//2$i ="ABS"+1;//1//the rest of the others have the same function.

  Notable in the operators are + + and--Two kinds:

  ++i, if a single row exists, then it is added +1, if in other statements appear participate in the operation, then the first to add 1 and then the operation;

i++; If a single row exists, then it is added +1, if there are other statements in the participation operation, then the first operation and then add 1;

I.; The same principle as ++i;

i--; The same principle as i++ ;

  2. String operators

  The most common string operators are used to manipulate strings in the longest use:

. and. =

Its main function is to connect strings.

  3. Assignment operators

There are several common assignment operators:

=,+=,-=,*=,/=,%=

The main function of such operators is to assign values to variables or to use them for operation. Because in JS Middle school, here is not in-depth record.

  4. Comparison operators

The common comparison operators are the following

>,<,>=,<=,==,!=,===,!==

The main is to judge the size of the operator on both sides of the relationship, the return is a Boolean value, mainly used in the judgment statement.

  It is noteworthy that if there is a Boolean value on either side of the operator, it is preferred to convert to a Boolean value for comparison, and if there is no Boolean value, the last comparison is a string.

In addition, floating-point numbers should not be involved in comparison operations.

true>1;//= true>ture; False resulttrue>"a";//= true>ture; False resulttrue>"";//= true>false; Result true"2">1;//= 2>1; Result true"3ab">1;//= 3>1; Result true//The same is true for other comparison operators

  5. Logical operators

There are three logical operators:

&& | | !

It is mainly for the logical operation.

$a && $b $a and $b are true at the same time. Another $ A is true before you run $b.

$a | | $b $a and $b at least one is true. Another $ A is fake before it runs $b.

! $a $a is true, the whole equation is false.

Also note: In the condition of judgment &&, | | Operators can improve performance by placing complex operations behind simple operations.

6. Ternary operators

  Also known as the conditional operator:

    

  The principle is the same as if statement, the condition is true, then executes the result one, the condition is false, then executes the result two. can be used instead of conditional statements.

  

7. Bitwise operators

The common bitwise operators have the following types of

      &: Bitwise AND

|: Bitwise OR

~: Bitwise REVERSE

^: Bitwise XOR OR

$n 2<<m: Bitwise left Shift

One of the most common ways that bit operators are used in PHP is to manage the switching state of a set of things.

1. With a variable, you can learn the current state of any data.

2. With a variable, you can "turn on" or "off" the state of a single data.

  8. Array operators

The following two pictures will understand

      

      

9. Error control operators

   There is only one error control operator:

      @

Usually used in one place: $link = @mysql_connect (), to prevent the browser from error and reveal information.

Ii. precedence of Operators

  Questions about the precedence of operators

Relatively speaking, today's knowledge is relatively simple, careful grasp of the details are OK.

Basic knowledge of PHP learning day5--operators

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.