2017-05-29 68 views
0

數組我有IP地址的數組,我想snmpwalk的這些IP地址,但我只能通過指定每個IP地址例如位置如何snmp的IP地址爲PHP

這是這樣做的我的ip地址陣列看起來像:

Array 
(
    [0] => 10.100.66.25 
    [1] => 10.96.100.1 
) 

在未來我會添加更多的IP地址。

這是我要執行的代碼SNMP:

$dbconnect=new mysqli('localhost','root','','helena'); 
$secondQuery = snmpwalk($switchArray[1], "iut-mon", ".1.3.6.1.2.1.17.4.3.1.1"); 

我怎麼會snmpwalk的陣列,而不是指定一個在所有的IP地址?

+0

隨着循環?一個簡單的foreach循環應該能夠做到這一點。 – Epodax

+0

謝謝。這有幫助。 –

回答

1

環陣列,並且合併的結果,就像下面的簡化:

$dbconnect = new mysqli('localhost','root','','helena'); 
$ips = ['10.100.66.25', '10.96.100.1']; 
$results = []; 

foreach ($ips as $key => $value) { 
    array_merge($results, snmpwalk($value, "iut-mon", ".1.3.6.1.2.1.17.4.3.1.1")); // add the array to the $results 
} 

print_r($results); // print the list of results array