Original: PHP 10: Process Control
Feel like PHP is similar to other languages.
Let's talk about the process Control keywords provided by PHP.
Conditions
if
Else
ElseIf
Switch
Cycle
while
Do
{
}
while()
Break
continue
For
Foreach
One thing to emphasize is foreach, whose syntax is:
foreach(Array_expression as $value)
Statement
foreach(Array_expression as $key = $value)
StatementThe first format iterates through the givenarray_expressionArray. In each loop, the value of the current cell is assigned to the$valueAnd the pointer inside the array moves forward one step (so the next one will be in the next loop).
The second format does the same thing, except that the key name of the current cell is assigned to the variable in each loop.$key。
In addition to the above, there are declare.declareStructure is used to set execution instructions for a piece of code.declaresyntax is similar to other process Control structures:
DECLARE (Directive) Statement |
directivesection allows you declare to set the behavior of the code snippet. Currently, only one command is implemented: ticks .
declareThe sections in the code snippet statement will be executed-how to execute and what side effects occur in the execution depend on directive the instructions set in.
declareThe structure can also be used for global scope, affecting all subsequent code.
The last is what we said earlier require,include,require_once,include_once. Don't say much.
Give me a few examples.
For require
1<?PHP
2
3require 'prepend.php';
4
5require $somefile;
6
7require ('Somefile.txt');
8
9?> For include
1VARs.PHP
2<?PHP
3
4$color = 'Green';
5$fruit = 'Apple';
6
7?>
8
9Test.PHP
Ten<?PHP
One
AEcho "A $color $fruit"; //A
-
-include 'vars.php';
the
-Echo "A $color $fruit"; //A Green Apple
-
-?>The others are similar.
The individual feels that the foreach is still somewhat confusing, please read the array and the use of foreach carefully.
PHP 10: Process Control