我正在学习php声明语句,我播下了以下php代码:
<?php
declare(ticks=1);
// A function called on each tick event
function tick_handler()
{
echo "<br>tick_handler() called ";
}
register_tick_function('tick_handler');
$a = 1;
if ($a > 0) {
$a += 2;
print($a);
}
?>产出:
tick_handler() called
tick_handler() called
tick_handler() called 3
tick_handler() called 我不明白为什么"tick_handler() called"要打印4次,为什么" tick_handler() called 3"出现在第三次print.please帮助我使用简单的explanation.thanks
发布于 2017-01-25 06:47:26
实际上,您很困惑,因为您的代码structure.It需要链接如下:-
<?php
declare(ticks=1); //this is a tick so tick_handler() will call and first time it outputs
// A function called on each tick event
function tick_handler()
{
echo "tick_handler() called ";
echo PHP_EOL;
}
register_tick_function('tick_handler');
$a = 1; // this a tick so again tick_handler() will call and second times output
if ($a > 0) {
$a += 2; // this is a tick so again tick_handler() will call and third times output
print($a);// it prints first the $a and because its a tick again so tick_handler() will call and fourth times output
}
?>注:-在链接的第二个示例中可以找到更清晰的图片:- http://php.net/manual/en/control-structures.declare.php#control-structures.declare.ticks
https://stackoverflow.com/questions/41844858
复制相似问题