我从带有PHP库的Zabbix获得信息。现在,我从json获得了"lastvalue“:
try {
// connect to Zabbix-API
$api = new ZabbixApi($api_url, $username, $password);
$params = array(
'groupids' => '2',
'real_items' =>TRUE,
'monitored_items' =>TRUE,
'search' => array('name' => 'Disk root used p'),
'selectFunctions' => 'extend',
'output' => 'extend',
'sortfield' => 'name',
'limit' => '1'
);
$trends = $api->itemGet($params); // get data from api
$names = array();
foreach($trends as $trend) { // loop through the returned data
$names[] = $trend->lastvalue;
}
//print_r($names);
} catch(Exception $e) {
// Exception in ZabbixApi catched
echo $e->getMessage();
}但是现在我想得到这个Array中的"lastvalue“加上条目的"name”,例如:"name"+"lastvalue“。如何将它们都放入数组$names[]中?
发布于 2015-11-12 10:53:36
这是我的回答,从我的意见,希望这是你正在寻找的!
$trends = $api->itemGet($params);
$names = array();
foreach($trends as $trendKey => $trendValue)
{
$names[$trendKey] = $trendValue;
}
#Test the names array
foreach ($names as $nameKey => $nameValue)
{
print("{$nameKey} = {$nameValue}<br />");
}返回值:
groupids = 2
real_items = TRUE
...
sortfield = name
limit = 1https://stackoverflow.com/questions/33669594
复制相似问题