Home >Backend Development >PHP Tutorial >PHP declare control characters and ticks tutorial (with examples)_PHP tutorial

PHP declare control characters and ticks tutorial (with examples)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:35:23776browse

The

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

Copy the code The code is as follows:

declare (directive)
statement

Don’t understand? The popular explanation is as follows: declare is the process control structure of PHP. Directive currently supports two instructions [ticks and encoding]. The use of ticks needs to be used in conjunction with the register_tick_function function (and of course the unregister_tick_function function). The ticks parameter indicates how many statements to run to call the register_tick_function function once.
The register_tick_function function defines the processing function when each tick event occurs. So what is a tick event?
ick is an event. The
tick event occurs 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 operation that should be performed when the tick event occurs.

The question comes again, what is a low-level statement? It includes:
Simple statements: empty statement (just a ; sign), return, break, continue, throw, goto, global, static, unset, echo, built-in HTML text, expressions terminated by semicolon, etc. are all counted a statement.
Compound statement: complete if/elseif, while, do...while, for, foreach, switch, try...catch, etc. are counted as one statement.
Statement block: statement block enclosed by {}.
The last special thing: the declare block itself is also a statement (it stands to reason that the declare block is also a compound statement, but it is deliberately separated here).

Look at a simple example:

Copy code 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}
";
      }
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/744330.htmlTechArticledeclare structure is used to set the execution instructions of a piece of code. Its syntax structure is as follows: Copy the code and the code is as follows: declare (directive) statement Don’t understand? The popular explanation is as follows: declare is...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn