473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Combine two arrays? Well, sort of...

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
3 8184
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Terry Richards | last post by:
this is prolly too simple but i got a brain block i have two arrays, one is days and the other is timeofday,<each letter represents a time on the hour> how do is sort by days and put each day's...
35
by: Troll | last post by:
Hi, I need to write a script which reads some data and reports the findings. Just to give you an idea the structure is similar to the following. Data input example: HEADING 1 **********...
6
by: Raistlin | last post by:
Hey, for c++ does any body have a way to compare two arrays? Say one has the numbers 1-5000, the other has *most* of the numbers from 1-5000, is there a way to display the numbers that are in the...
6
by: Xiaozhu | last post by:
say, if you had parallel arrays containing the sales person id, the month, and the sales figures (for that person in that month), sorting on sales figure and preserve the order of figures within...
3
by: cpuracr8 | last post by:
i've been looking through the topics here and i can't quite find one that helps me. i'm trying to sort a struct that contains three arrays using the sort() function. the three arrays are parallel...
0
by: Jeff Talley | last post by:
Wanting to combine the elements of two arrays into one. Have also tried to combine the two into a new struct, but cannot seem to update an instance of a struct once it is created. Example:...
2
by: chris | last post by:
I have a few byte arrays that I would like to combine into one array (order needs to be kept). What would be the most efficient way to do this? Thanks for your time, Chris
2
by: abcjayati | last post by:
can anyone give me a program that a combines two arrays of size 10 in another array and sort them in ascending order.
1
by: chiefychf | last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.