PHP有沒有類似JS setTimeout的函數
2 回答
jeck貓
TA貢獻1909條經驗 獲得超7個贊
沒有,不過可以通過sleep函數來實現。
代碼:
| 1234567891011121314151617 | function setTimeout($func, $sec = 0, $timeout = 0, $args = array()) { if (!function_exists($func) || $timeout == 0) { return false; } while ($timeout > 0) { if (!empty($args) && is_array($args)) { call_user_func_array($func, $args); } else { call_user_func($func, $args); } flush(); ob_flush(); sleep($sec); $timeout--; } return false;} |
- 2 回答
- 0 關注
- 762 瀏覽
添加回答
舉報
0/150
提交
取消
