为什么我的代码说$ publishRequest是未定义的。它确实是在数组中定义的
这只是我的代码的一部分,但这部分是问题隐藏的部分
已经在数组上方尝试过:
php
$publishRequest = array()
if($status1=="up") {
$publishRequest = array(
"instance_id" => INSTANCE_ID,
"name" => INSTANCE_NAME,
"group" => INSTANCE_GROUP,
"description" => "Running on Controller.Ligowave.com",
"contents" => array(
array(
"name" => "Status",
"contents" => array(
array(
"icon" => "information",
"type" => "label",
"title" => $name1,
"subtitle" => "Uptime is: " . $uptimetime1
)
)
)
)
);
} else {
array(
"icon" => "error",
"type" => "label",
"title" => $name1,
"subtitle" => "Down since: " . $lastseendate1);
}
try {
echo "<p>Publish</p>";
$publishResponse = request(options, $publishRequest);
echo "<p>".$publishResponse."</p></br></br>";
}
答案 0 :(得分:2)
如果$status1
不是== 'up'
,则可以在ELSE中创建一个数组,但不要将其设置为变量$publishRequest
else {
$publishRequest = array(
"icon" => "error",
"type" => "label",
"title" => $name1,
"subtitle" => "Down since: " . $lastseendate1);
}