比较多维数组并获取匹配键的值

时间:2014-10-13 20:45:14

标签: php

我有两个要比较的多维数组,我必须得到只有匹配键的键和值。

我的第一个阵列:

stdClass Object
(
[CPU load] => Array
(
[0] => load1
[1] => load5
[2] => load15
)

[CPU utilization] => Array
(
[0] => user
[1] => wait
)

[Disk IO SUMMARY] => Array
(
[0] => read
[1] => write
)

[Interface 2] => Array
(
[0] => in
[1] => inucast
[2] => innucast
[3] => indisc
[4] => inerr
[5] => out        
[6] => outucast        

)


)

我的第二个阵列:

array(
[1] => Array
(
[_id] => MongoId Object
(
[$id] => 543ad15bc863c7b96b3b3d81
)

[hosts_group_name] => my all groups
[hosts_and_services] => Array
(

[Redmine] => Array
(
[0] => Disk IO SUMMARY
[1] => Interface 2
)

)

[customerIdentifier] => devmaas
)

)

)

我想要的是:

$graph=array('Disk IO SUMMARY'=>array('load1','load5','load15'),
'Interface 2'=>array('user','wait'));

我尝试的是:

$newarray1=array(); 
$newarray2=array(); 
foreach ($this->graphMap as $key => $val) {
    $newarray1[]=$key;
}
foreach ($select_host_group_details as $group_details){
    foreach($group_details['hosts_and_services'] as $key=>$val){
        foreach($val as $k=>$v){
            $newarray2[]=$v;
        } 
    }
}
if($newarray1==$newarray2)
{
}

帮助我,我没有得到如何比较它并组合这些数组。

0 个答案:

没有答案