我能够从远程设备提取信息,但输出是一个相当大的数组,我在格式化语法时遇到了问题。我的数组输出如下所示;
array(420) { [0]=> object(stdClass)#2 (3) { ["Name"]=> string(99) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\CallsActive" ["Value"]=> int(3) ["CStatus"]=> int(1) } [1]=> object(stdClass)#3 (3) { ["Name"]=> string(102) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\CallsCompleted" ["Value"]=> int(172) ["CStatus"]=> int(1) } [2]=> object(stdClass)#4 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 1 Status" ["Value"]=> int(3) ["CStatus"]=> int(1) } [3]=> object(stdClass)#5 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 2 Status" ["Value"]=> int(3) ["CStatus"]=> int(1) } [4]=> object(stdClass)#6 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 3 Status" ["Value"]=> int(3) ["CStatus"]=> int(1) } [5]=> object(stdClass)#7 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 4 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [6]=> object(stdClass)#8 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 5 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [7]=> object(stdClass)#9 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 6 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [8]=> object(stdClass)#10 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 7 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [9]=> object(stdClass)#11 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 8 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [10]=> object(stdClass)#12 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 9 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [11]=> object(stdClass)#13 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 10 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [12]=> object(stdClass)#14 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 11 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [13]=> object(stdClass)#15 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 12 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [14]=> object(stdClass)#16 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 13 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [15]=> object(stdClass)#17 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 14 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [16]=> object(stdClass)#18 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 15 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [17]=> object(stdClass)#19 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 16 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [18]=> object(stdClass)#20 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 17 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [19]=> object(stdClass)#21 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 18 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [20]=> object(stdClass)#22 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 19 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [21]=> object(stdClass)#23 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 20 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [22]=> object(stdClass)#24 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 21 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [23]=> object(stdClass)#25 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 22 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [24]=> object(stdClass)#26 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 23 Status" ["Value"]=> int(2) ["CStatus"]=> int(1) } [25]=> object(stdClass)#27 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 24 Status" ["Value"]=> int(4) ["CStatus"]=> int(1) } [26]=> object(stdClass)#28 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 25 Status" ["Value"]=> int(0) ["CStatus"]=> int(1) } [27]=> object(stdClass)#29 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 26 Status" ["Value"]=> int(0) ["CStatus"]=> int(1) } [28]=> object(stdClass)#30 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 27 Status" ["Value"]=> int(0) ["CStatus"]=> int(1) } [29]=> object(stdClass)#31 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 28 Status" ["Value"]=> int(0) ["CStatus"]=> int(1) } [30]=> object(stdClass)#32 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 29 Status" ["Value"]=> int(0) ["CStatus"]=> int(1) } [31]=> object(stdClass)#33 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 30 Status" ["Value"]=> int(0) ["CStatus"]=> int(1) } [32]=> object(stdClass)#34 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\Channel 31 Status" ["Value"]=> int(0) ["CStatus"]=> int(1) } [33]=> object(stdClass)#35 (3) { ["Name"]=> string(105) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\DatalinkInService" ["Value"]=> int(1) ["CStatus"]=> int(1) } [34]=> object(stdClass)#36 (3) { ["Name"]=> string(108) "\\ip_address\Cisco MGCP PRI Device(gateway01.domain.com::S0_SU0_DS1-0)\OutboundBusyAttempts" ["Value"]=> int(0) ["CStatus"]=> int(1) } [35]=> object(stdClass)#37 (3) { ["Name"]=> string(99) "\\ip_address\Cisco MGCP PRI Device(gateway02.domain.com::S0_SU0_DS1-0)\CallsActive" ["Value"]=> int(0) ["CStatus"]=> int(1) } [36]=> object(stdClass)#38 (3) { ["Name"]=> string(102) "\\ip_address\Cisco MGCP PRI Device(gateway02.domain.com::S0_SU0_DS1-0)\CallsCompleted" ["Value"]=> int(109) ["CStatus"]=> int(1) } [37]=> object(stdClass)#39 (3)
我有兴趣为gateway02获取CallsActive的整数。所以,我知道这种语法将允许我打印所有对象" Name&#34 ;;
foreach($devices as $first)
{
$Name = $first->Name;
echo $Name;
}
你如何解析这个数组?
答案 0 :(得分:1)
foreach($devices as $device){
if((strpos($device->Name,'gateway02') !== false)&& (strpos($device->Name,'CallsActive') !== false)){
echo $device->Name . " : " . $device->Value;
}
}
使用strpos检查名称是否包含这些值,如果是,请使用它执行某些操作。