不久前我写了一个脚本,但在过去几天遇到了一些问题,我在查看它时注意到我没有正确填充变量。在 PHP 中删除变量并将其填充到子范围中的正确方法是什么?我当前的代码如下所示,但我遇到了 $results 变量未填充的问题。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $GLOBALS["api_url"]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);
$data = explode(";",$data);
$results = array();
foreach ($data AS $temp)
{
$temp = explode("=",$temp);
$results[$temp[0]] = $temp[1];
}
if ($results["result"] == "success")
{
$log_terminate_success = "Service ID #" . $serviceid . " has been Immediately Terminated Successfully!";
log_activity($log_terminate_success);
return true;
}
else
{
$log_terminate_failure = "Service ID #" . $serviceid . " has failed Immediate Termination: " . $results["message"];
log_activity($log_terminate_failure);
return false;
}