Process Control in PHP

Source: Internet
Author: User

If
if () {    statement;} else if {    statement;} elseif {    statement;} else {    statement;}

else ifelseifis a little different from the meaning of syntactic analysis, but the bottom line is that they produce exactly the same behavior.

Cycle
while () {    statement;}do {    statement;} while();for (;;) {    statement;}foreach (as) {    statement;}                   
Break, continue

Can accept an optional numeric parameter to decide to jump out of a few loops

Switch
switch () {    case :        statement;    default:        statement;}

Allow colons to be substituted for case statements using semicolons

switch ($beer) {    case ‘tuborg‘;    case ‘carlsberg‘;    case ‘heineken‘;        echo ‘Good choice‘;    break;    default;        echo ‘Please make a new selection...‘;    break;}
Declare

The declare structure is used to set execution instructions for a piece of code.

Currently only two commands are known: Ticks and encoding

Ticks

Tick (clock cycle) is an event that occurs in the declare code snippet when an interpreter executes an N-timed low-level statement. The value of N is specified in the directive section of declare with Ticks=n.

Not all statements can be timed. Neither the conditional expression nor the parameter expression is timed.

The tick represents an event in which the event is defined in Register_tick_function, and the frequency at which the event is executed is at (ticks=n).

Use, triggering an event every time a few statements are executed, such as logging an event. This allows you to check the execution speed of PHP code within the declare. You can find the code snippet location where the slower part occurs.

<?php    function doTicks ()    {        echo ‘Ticks‘;    }    register_tick_function(‘doTicks‘);    declare(ticks = 1) {        for ($x = 1; $x < 10; ++ $x) {            echo $x * $x . ‘<br />‘;        }    }?>

Result of Operation:

1TicksTicks4TicksTicks9TicksTicks16TicksTicks25TicksTicks36TicksTicks49TicksTicks64TicksTicks81TicksTicksTicksTicks

First, the complete for Loop calculates a statement, but must wait until the end of the loop, so the echo in the for loop at compile time is the first statement.
So the first doticks is executed after the first echo, that is, the first tick event occurs after the 1 output.
In x from1to the9of theFollowRingin,everyaFollowRingPackageincludingtwoalanguagesentence,aaeCho,aaF oR FollowRing. in theBayiloseoutafter,becauseto beeChois aaStriplanguagesentence,becausethisloseoutSectionaaT ICk s. withwhen X=9 this for loop also ends, this is another statement, output the second ticks, start the $x=10 loop, but at this time the loop condition is not satisfied, the For loop execution ends, this loop is a statement, then output a third ticks.
Finally declare itself is counted as a statement, so the fourth ticks is output.

Encoding

You can use the encoding directive to specify how each script is encoded

<?phpdeclare(encoding=‘ISO-8859-1‘);// code here?>
Reutrnrequire, include, require_once, include_once

Require and include are almost exactly the same, in addition to handling failures differently. Require generates an E_COMPILE_ERROR level error when an error occurs. In other words, the script aborts and the include generates only warnings (e_warning), and the scripts continue to run.

Goto

The goto operator can be used to jump to another location in the program. The target location can be marked with a colon for the target name, and the jump instruction is the mark after Goto followed by the target location.

There are certain restrictions on Goto in PHP, where the target location can only be in the same file and scope, that is, you cannot jump out of a function or class method, or you can skip into another function. You cannot jump into any loop or switch structure. You can jump out of a loop or switch, usually using Goto instead of a multi-layered break.

<?phpgoto a;echo ‘Foo‘;a:echo ‘Bar‘;?>

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Process Control in PHP

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.