The declare structure is used to set the execution instructions for a section of code, and its syntax is structured as follows:
DECLARE (Directive)
Statement
Don't understand? The popular explanation is as follows:
The ticks parameter represents a function that runs the number of statements called once register_tick_function.
The Register_tick_function function defines the handler function at the time each tick event occurs. So what is the tick incident?
Tick is an event.
The Tick event occurs one time in PHP for each execution of n low-level statements, and n is specified by the Declare statement.
You can use Register_tick_function () to specify the action that should be taken when the tick event occurs.
The question comes again, what is the low-level statement? It includes:
Simple statements: Empty statements (just A; number), return, break, continue, throw, Goto, Global, Static, unset, ECHO, built-in HTML text, semicolon-terminated expression, etc.
Compound statement: The complete If/elseif, while, Do...while, for, foreach, switch, try...catch, etc. are counted as a statement.
Statement BLOCK: A block of statements enclosed in {}.
Finally Special: Declare block itself is also a statement (according to the reason declare block is also considered a compound statement, but here deliberately separate it out).
Look at a simple example:
The code is as follows |
Copy Code |
/** * DECLARE * @link http://www.111cn.net */ function Do_tick () { echo "<font color=red>do_tick</font>"; }
Register_tick_function (' Do_tick ');
DECLARE (ticks = 1) { for ($i = 1; $i < 5; $i + +) { echo "<font color=blue>{$i}</font><br>"; } } |
The results of the above procedure:
PHP declare control characters and ticks detailed tutorials explain the results:
The first time into the For loop, the first Do_tick function is performed after the Echo is executed;
After the first for loop ends, the second Do_tick function is executed;
Cycle four times ... ;
The fifth time for the loop, the condition is not satisfied, for the loop end, the execution of a do_tick function;
The declare itself is also a statement, and the Do_tick function is executed once.
As can be seen from the above, declare and ticks can be used for debugging or performance testing.