Source: Internet
Author: User

An operator is something that can produce another value (thus the entire structure becomes an expression) by giving one or more of the values (in programming jargon, an expression).

The first is a unary operator, which only operates a single value, for example! (Take the inverse operator) or + + (plus an operator).

Example

1, the use of ++i (A=++i, i=2 as an example)

First add the I value by 1 (that is, i=i+1), and then assign the variable a (that is, a=i),

The final a value is equal to 3, and the I value equals 3.

So a=++i is equivalent to i=i+1, a=i

2, the use of i++ (a=i++, i=2 as an example)

First assigns the I value to the variable a (that is, a=i), and then the I value plus 1 (that is, i=i+1),

The final a value is equal to 2, and the I value equals 3.

So a=i++ is equivalent to A=i, i=i+1

3, ++i and i++

A=++i is equivalent to i++, a=i

a=i++ is equivalent to A=i, i++

4, ++i and i++ when used alone, the equivalent of i=i+1

If you assign a new variable, ++i first adds the I value to 1, and i++ first assigns I to the new variable

The second is the two-dollar operator, which accepts two values, such as the familiar arithmetic Operators + (plus) and-(minus), and most PHP operators are these

$a =1+2;

$b = 3-1;

The third is the ternary operator, which accepts three values and should be used to select one of the other two expressions based on an expression, rather than to select it in two statements or program routes. (also referred to as a conditional operator may be more appropriate)

The code format is as follows: (EXPR1)? (EXPR2): (EXPR3);

For example: $page =!empty ($_get[' page '])? $_get[' Page ']: 1;

Related Article