By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,759 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,759 IT Pros & Developers. It's quick & easy.

Combine two arrays? Well, sort of...

P: n/a
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
Sep 19 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Try a multidimensonal array
$ar[0][0]= "Serial0";
$ar[0][1]= "PPP T1 to Customer";
etc
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
Sep 19 '06 #2

P: n/a

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?

Sep 20 '06 #3

P: n/a
davie wrote:
Try a multidimensonal array
$ar[0][0]= "Serial0";
$ar[0][1]= "PPP T1 to Customer";
etc
I think that is the way to go instead of a simple append. I am just not sure
how to combine the two arrays into one multi-dimensional array.

Thank you for the help!
>

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

Sep 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.