Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Combine two arrays? Well, sort of...
- Schroeder, AJ
September 19, 2006, 9:58 pm
rate this thread
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
[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:
[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
Any help on this is appreciated!
Re: Combine two arrays? Well, sort of...
Schroeder, AJ wrote:
$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
'OLD-CISCO-INTERFACES-MIB::locIfDescr.2' => "Ethernet to
'OLD-CISCO-INTERFACES-MIB::locIfDescr.3' => "",
'OLD-CISCO-INTERFACES-MIB::locIfDescr.4' => "");
$arr3 = $arr1 + $arr2;