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