PHP 10: Process Control

Source: Internet
Author: User
Tags vars

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

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.