PHP's Process Control

Source: Internet
Author: User
Tags unpack

Nest nesting
The curly braces curly braces
Colon syntax colon syntax

PHP Three if the wording of the judgment

Writing one:
if (true) {
}else if () {
}else if () {
}else{}

Two:
if () {
}elseif () {
}elseif () {
}else{}

Three:
if ():
#执行语句
ElseIf
#执行语句
ElseIf
#执行语句
Else
#执行语句
endif

Alternative syntax for Process Control

PHP provides a number of alternative syntax for process Control,
Includes If,while,for,foreach and switch.
The basic form of substitution syntax is to replace the left curly brace ({) with a colon (:),
Replace the right curly brace (}) with Endif;,endwhile;,endfor;,endforeach; and Endswitch;.

Note:

It is not supported to mix two syntaxes within the same control block.

Echo and print are statement structures, not functions, and cannot be used as callback functions

But print always returns 1.

Foreach

A reference to a $value is available only if the array being traversed can be referenced (for example, a variable). The following code does not work:

It is easy to modify the elements of an array by adding & before $value. This method assigns a value to a reference instead of copying a value.
Warning
The $value reference of the last element of the array remains after the Foreach loop. It is recommended to use unset () to destroy it.

Unpack nested arrays with list ()

(PHP 5 >= 5.5.0, PHP 7)

PHP 5.5 adds the ability to iterate through an array of arrays and unpack the nested array into a loop variable by simply supplying the list () as a value.

The cells in list () can be less than the nested arrays, and the extra array cells are ignored:
If more cells are listed in list () than nested arrays, a message-level error message is emitted:

Added: Declare, require, require_once, include, Include_once?????????????????

PHP's 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.