Php (3) operator and Process Control

Source: Internet
Author: User
Tags switch case
I. Operator 1. Arithmetic Operator-$ a is used to take the negative value of $. $ A $ B adds the sum of $ a and $ B. $

I. Operator 1. Arithmetic Operator-$ a is used to take the negative value of $. $ A $ B adds the sum of $ a and $ B. The difference between $ a-$ B subtraction $ a and $ B. The product of $ a * $ B multiplication $ a and $ B. $ A/$ B Division $ a divided by the operator of $ B. $ A % $ B modulo $ a divided by the remainder of $ B. Note: Generally, the Division operator returns a floating point number. However

I,Operator

1. ArithmeticOperator

-$ Invert $.
$ A + $ B Addition $And$ BAnd.
$ A-$ B Subtraction $And$ B.
$ A * $ B Multiplication $And$ B.
$ A/$ B Division $Divided$ B.
$ A % $ B Modulo $Divided$ B.
Note:

Division in generalOperatorReturns a floating point number. However, if both operands are integers (or strings converted to integers) and can be fully divided, then it returns an integer.

ModuloOperatorThe operand is converted to an integer (excluding the decimal part) before the operation ).

ModuloOperator %The result is the same as the divisor. That is$ A % $ BResults and$.

2. BitOperator

$a & $b And (bitwise And) $And$ BThe bits whose values are both 1 are set to 1.
$a | $b Or (by bit Or) $And$ BAny bit with a value of 1 in is set to 1.
$a ^ $b Xor (by bit or) $And$ BOne is 1 and the other is 0.
~ $a Not (bitwise inversion) Set$Set 0 to 1, and vice versa.
$a << $b Shift left (left Shift) Set$The bitwise in moves to the left$ BTimes ("multiplied by 2 ").
$a >> $b Shift right (right Shift) Set$The bitwise in moves to the right.$ B(Each Movement indicates "divided by 2 ").
Note: displacement is a mathematical operation in PHP. Bits removed from any direction are discarded. When the Left shift is performed, the right side is filled with zero. When the symbol bit is removed, the plus and minus signs are not retained. When the right shift is performed, the left side is filled with signs, which means the plus and minus signs are retained.

3. ComparisonOperator

$ A = $ B Equal TRUEIf the type is converted$Equal$ B.
$ A ===$ B Full TRUE, If$Equal$ BAnd their types are the same.
$! = $ B Not Supported TRUEIf the type is converted$Not equal$ B.
$ A <> $ B Not Supported TRUEIf the type is converted$Not equal$ B.
$! ==$ B Incomplete TRUE, If$Not equal$ BOr they have different types.
$ A <$ B Xiaohe TRUE, If$Strictly less$ B.
$ A> $ B Greater TRUE, If$Strictly greater$ B.
$ A <= $ B Less than or equal TRUE, If$Less than or equal$ B.
$ A> = $ B Greater than or equal TRUE, If$Greater than or equal$ B.
Note: If you compare a number with a string or a string that involves the content of a number, the string is converted to a value and compared to a value.

For multiple types, comparisonOperatorComparison based on the following table:

Null or string String SetNULLConvert to "" For comparison of numbers or words
Bool or null Any other type Convert to bool,FALSE<TRUE
Object Object Built-in classes can define their own comparisons. Different classes cannot be compared. The same classes and arrays are used to compare attributes (in PHP 4). PHP 5 has its own instructions.
String, resource, or number String, resource, or number Converts a string and a resource to a number and compares it by common mathematics.
Array Array The array with fewer members is small. If the key in Operation Number 1 does not exist in Operation Number 2, the array cannot be compared. Otherwise, compare the values one by one (see the following example)
Object Any other type The object is always larger.
Array Any other type Array is always larger
4. Error Control Operator

PHP supports an errorControlOperator: @ When it is placed before a PHP expression, any error information that may be generated by this expression is ignored.

5. ExecuteOperator

PHP supports one executionOperator: Back quotes (''). PHP will try to execute the content in the back quotes as a shell command and return its output information.

6. Auto-increment/auto-IncrementOperator

++ $ Add $And then return$.
$ A ++ Houjia Return$, And then$Value plus one.
-- $ Minus $And then return$.
$ -- Subtraction Return$, And then$Value minus one.
7. Logic Operator

$ A and $ B And (logical And) TRUE, If$And$ BAllTRUE.
$ A or $ B Or (logical Or) TRUE, If$Or$ BAny oneTRUE.
$ A xor $ B Xor (logical exclusive or) TRUE, If$Or$ BAny oneTRUEBut not at the same time.
! $ Not (logical non) TRUE, If$NotTRUE.
$ A & $ B And (logical And) TRUE, If$And$ BAllTRUE.
$ A | $ B Or (logical Or) TRUE, If$Or$ BAny oneTRUE.
8. Array Operator

$ A + $ B Union $And$ B.
$ A = $ B Equal If$And$ BIf you have the same key/value pairTRUE.
$ A ===$ B Full If$And$ BKey/value pairs with the same sequence and type areTRUE.
$! = $ B Not Supported If$Not equal$ BIsTRUE.
$ A <> $ B Not Supported If$Not equal$ BIsTRUE.
$! ==$ B Incomplete If$Not equal$ BIsTRUE.

9. Type Operator

InstanceofUsed to determine whether a PHP variable belongs to an instance of a class.

10,OperatorPriority

Integration direction

Operator

None

Clone new

Left

[

Right

++ --~ (Int) (float) (string) (array) (object) (bool )@

None

Instanceof

Right

!

Left

*/%

Left

+ -.

Left

<>

None

=! ===! ==<>

Left

&

Left

^

Left

|

Left

&&

Left

|

Left

? :

Right

= + =-= * =/=. = % = & =|=^= <<=>>=>

Left

And

Left

Xor

Left

Or

Left

,


II, Process Control

If else statement;

SanyuanOperator:( Expr )? (Contents) :( contents), similar to the C language;

Switch case statement;

For, wihle, do while loop;

Break and continue jump statements;

Foreach loop:

foreach (array_expression as $value)    statementforeach (array_expression as $key => $value)    statement
Return Statement;

Require and include statements: contain and run specified files. However, the processing failure method is different,RequireGenerated when an error occursE_COMPILE_ERRORLevel Error, causing the script to stop running, while include only generates a warning (E_WARNING), The Script continues to run.

Include_once and require_once statements: similar to include statements, the only difference is that if the file has been included, it will not be included again.

Goto statement:GotoThe operator can be used to jump to another position in the program. The target location can be marked by the target name with a colon, and the jump command isGotoThen mark the target location. In PHPGotoThere are some restrictions. The target location can only be in the same file and scope. That is to say, you cannot jump out of one function or class method, or jump into another function. And cannot jump into any loop or switch structure. Can jump out of the loop or switch, the general usage is to useGotoReplace multiple layersBreak.

Ddeclare statement:

DeclareStructure is used to set the execution instructions for a piece of code.

declare (directive)    statement
DirectivePartially allowed DeclareThe behavior of the code segment. Currently, only two commands are known: TicksAnd Encoding

The Tick (clock cycle) is an interpreter in the declare code segment for every executionNA low-level statement that can be timed.NThe value is used in the directive section of declare.ticks=N.

Not all statements can be timing. Generally, conditional expressions and parameter expressions do not support timing.

The events that occur in each tick are specified by register_tick_function.

Example:

Declare (ticks = 1 );

// A function called on each tick event
Function tick_handler ()
{
Echo "tick_handler () called \ n ";
}

Register_tick_function ('tick _ handler ');

$ A = 1;

If ($ a> 0 ){
$ A + = 2;
Print ($ );
}

Output: tick_handler () called 3tick_handler () called tick_handler () called

The so-called low-level statements include statement, function_declare_statement, and class_declare_statement.

Statement includes:

(1) simple statement: empty statement (just one; number), return, break, continue, throw, goto, global, static, unset, echo, built-in HTML text, a semicolon-terminated expression is considered as a statement.

(2) composite statement: the complete if/elseif, while, do... while, for, foreach, switch, try... catch statements are considered as one statement.

(3) Statement block.

Explain the reason for the above output:

1. $ a = 1;

2. if statement judgment condition is true;

3. $ a + = 2;

4. print statement; (therefore, the previous output is tick_handler () called and $ a is 3 ;)

5. The if statement condition is not true;

6. Define the tick_handler () statement;

7. register_tick_handler () statement;

8. declare () statement. (So output tick_handler () called four times again)



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.