Branching and looping
1. If the judging condition
Is_bool (): Determines whether it is a Boolean type
Is_int (), Is_integer (), and Is_long (): Determines whether it is an integral type.
Is_float (), is_double (), and Is_real (): Determines whether it is a floating-point type
Is_string (): Determines whether it is a string
Is_array (): Determines whether the array
Is_object (): Determines whether the object
Is_resource (): Determines whether the resource type
Is_null (): Determines whether it is null
Is_scalar (): Determines whether it is a scalar
Is_numeric (): Determines whether it is any type of numeric and numeric string
Is_callable (): Determine if the function name is valid
2, ElseIf
In PHP, ElseIf statements can be ligatures or separated by spaces;
For example:
else if () √
ElseIf () √
3. Switch
In PHP, the switch structure is judged using = = rather than = = =
In PHP, continue can be used with the switch structure, with the same effect as break.
In PHP, continue and break can be followed by numbers, which means skipping several layers of loops or switch;
Eg:break 3; Indicates terminating 3-layer loop
4. Do-while Cycle
Do-while the end of the loop must be added with a semicolon.
do{
}while ();
5. Process Control Statements
1. Break: Terminates the loop of this layer; A number can be followed by a break, which means that several layers of loops are terminated. Break 3 to terminate the 3-layer loop.
2, continue: skip this cycle; Continue can also be followed by numbers, which means skipping several layers of loops
3, return: Terminates the current function, and returns the value (if any), but generally only used in the function, the script does not recommend the use of return;
4, exit (mixed concluding)/die (mixed concluding) function: Directly end the current PHP script!!
If a parameter is passed in, the closing is printed first, and then the current script is ended.
Goto
1. Usage:
Define a jump anchor point, "identifier"--"JR:"
In any position, set the goto statement to jump to the specified anchor point: "Goto JR;"
2. Function:
Jumps directly to the set identifier location when a goto statement is encountered.
3, used to implement the branch.
Note: The goto statement simply jumps the current program control flow to the specified anchor point, but is not responsible for executing a few lines of code down.
That is, all the code down from the anchor point executes sequentially. If you implement a Multipath branch, you need to match the Goto statement to skip the other branches. (see case study below)
4. Goto Implementation Loop:
See the case. However, in Goto, jumping out of a loop cannot use break.
5. The advantages and disadvantages of goto statement:
① Advantages: The use of flexible and convenient, instruction-level statements, faster efficiency, better performance.
② Cons: The massive use of Goto is a disaster for the structuring of the code.
It is not conducive to a clear code structure, is not conducive to understanding the code, and it is very likely to skip some important declaration statements, resulting in code errors.
PHP branching with loops and Goto