|
Posted by Chung Leong on 09/20/06 01:46
Schroeder, AJ wrote:
> Hello group,
>
> I am a relative PHP newbie and I am trying to combine two arrays together,
> but I also need to keep the keys of one array intact. What I am doing is two
> SNMP walks against a Cisco router in which I expect the script to return the
> interface number along with a small description of the interface type, like
> this:
>
> Array
> (
> [IF-MIB::ifDescr.1] => Serial0
> [IF-MIB::ifDescr.2] => FastEthernet0
> [IF-MIB::ifDescr.3] => Null0
> [IF-MIB::ifDescr.4] => Loopback100
> )
>
> I also am doing another SNMP walk to gather the user-defined description of
> each interface (which is keyed off of the interface number). Here is the
> output I get from that:
>
> Array
> (
> [OLD-CISCO-INTERFACES-MIB::locIfDescr.1] => "PPP T1 to Customer"
> [OLD-CISCO-INTERFACES-MIB::locIfDescr.2] => "Ethernet to LAN"
> [OLD-CISCO-INTERFACES-MIB::locIfDescr.3] => ""
> [OLD-CISCO-INTERFACES-MIB::locIfDescr.4] => ""
> )
>
> I would like to combine the arrays, but I would like to preserve the keys
> and values from the first array, but also append the values of the second
> array (don't really care about the keys, they *should* line up).
>
> I looked into the array_combine function, but that takes the values from the
> first array and makes them the keys for a new array.
>
> My ultimate goal is to output this to an HTML table, but the data is not
> lining up as I expected since when I join/combine the arrays, I lose my
> keys.
>
> Any help on this is appreciated!
>
> Thanks,
>
> AJ Schroeder
$arr1 = array('IF-MIB::ifDescr.1' => "Serial0",
'IF-MIB::ifDescr.2' => "FastEthernet0",
'IF-MIB::ifDescr.3' => "Null0",
'IF-MIB::ifDescr.4' => "Loopback100");
$arr2 = array('OLD-CISCO-INTERFACES-MIB::locIfDescr.1' => "PPP T1 to
Customer",
'OLD-CISCO-INTERFACES-MIB::locIfDescr.2' => "Ethernet to
LAN",
'OLD-CISCO-INTERFACES-MIB::locIfDescr.3' => "",
'OLD-CISCO-INTERFACES-MIB::locIfDescr.4' => "");
$arr3 = $arr1 + $arr2;
var_dump($arr3);
Easy, huh?
Navigation:
[Reply to this message]
|