目前,您只在完成所有操作后才回顯數據,而不是在數據完成時回顯數據。為了實現這一點,您需要通過分離每個函數所關心的或需要關心的內容來re-structure您的代碼。 例如,您需要一個函數來發出POST請求,但它不必知道任何關于數據本身的信息—它只需要發送請求和接收響應。它甚至不需要知道如何處理錯誤: /** * Send POST requests to given URL with given data. * * @return array */function http_post(string $url, string $data): array { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $error = curl_error($ch); curl_close ($ch); // Just return right away, do not be concerned with anything