gpt4 book ai didi

php - PHP 脚本可以在 exit() 之前执行普通代码吗?

转载 作者:可可西里 更新时间:2023-11-01 13:03:30 26 4
gpt4 key购买 nike

如何在 PHP 脚本中完成类似以下的操作?

 code{
$result1 = task1() or break;
$result2 = task2() or break;
}

common_code();
exit();

最佳答案

在 PHP help doco 中,您可以指定在 exit() 之后但在脚本结束之前调用的函数。

请随时查看 doco 了解更多信息 http://us3.php.net/manual/en/function.register-shutdown-function.php

<?php
function shutdown()
{
// This is our shutdown function, in
// here we can do any last operations
// before the script is complete.

echo 'Script executed with success', PHP_EOL;
}

register_shutdown_function('shutdown');
?>

关于php - PHP 脚本可以在 exit() 之前执行普通代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1436189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com