Php declare controller and ticks tutorial (example)

Source: Internet
Author: User
Declare is the PHP process control structure. directive currently supports two commands. The use of ticks must be used with the register_tick_function function. See the following small example.

Declare is the PHP process control structure. directive currently supports two commands. The use of ticks must be used with the register_tick_function function. See the following small example.

The declare structure is used to set the execution command of a piece of code. Its syntax structure is as follows:

The Code is as follows:


Declare (directive)
Statement

Don't you understand? The general explanation is as follows: declare is the PHP process control structure. directive currently supports two commands [ticks and encoding]. The use of ticks must be used in combination with the register_tick_function function (of course, The unregister_tick_function function. The ticks parameter indicates how many statements are run to call the register_tick_function function once.
The register_tick_function function defines the processing function for each tick event. So what is a tick event?
Ick is an event.
The tick event occurs once every time N low-level statements are executed in PHP, and N is specified by the declare statement.
You can use register_tick_function () to specify the operations that should be performed when a tick event occurs.

The problem arises again. What is a low-level statement? It includes:
Simple statement: empty statement (just one; number), return, break, continue, throw, goto, global, static, unset, echo, built-in HTML text, a semicolon-terminated expression is considered as a statement.
Composite statement: the complete if/elseif, while, do... while, for, foreach, switch, try... catch and so on are regarded as a statement.
Statement block.
The last note is that the declare block itself is also a statement (in principle, the declare block is also a composite statement, but it is specially isolated here ).

Let's look at a simple example:

The Code is as follows:


Function do_tick ()
{
Echo "do_tick ";
}
Register_tick_function ('Do _ tick ');

Declare (ticks = 1)
{
For ($ I = 1; $ I <5; $ I ++)
{
Echo "{$ I}
";
}
}

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.