473,695 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8202
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
1849
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 list in order of time? so that i get a list in order of days and each day is in order of time...i can put in order by day or time but they always end up with whatever is the other order wrong. if ( isset($_GET) && $_GET=='call_days' ) {
35
3661
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 ********** ColumnA ColumnB ColumnC ColumnD ColumnE
6
10569
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 1st array, but not in the 2nd array? Or load those numbers in a 3rd array? Thats the simple version...there are a couple other problems: ex: the 10th value of the 2nd array corresponds to the 12th value of the first. - you cant simply make a...
6
3527
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 the data about the same person: Original Data: id month sales +-----+ +-----+ +-----+ | 432 | | 8 | | 89 | +-----+ +-----+ +-----+ | 123 | | 8 | | 116 |
3
2785
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 and need to be grouped together when it is sorted. for instance, if i sort the int array by ascending order, i need the name and grade associated with that int array to also move with it. i hope what i said is not too confusing. what am i doing...
0
3309
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: ArrayA contains the hole number and score for a golfer's round. ArrayB contains the hole number and par for the hole. Want ArrayC which contains hole number, score, and par.
2
7900
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
2432
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
3113
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 a,b,c into another array f.. I can do two arrays, but I have issues when trying to do all three and when I do the even/odd compare I only get 2 numbers processed. here is some of the code... //*******************Function...
0
8630
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8568
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8845
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8825
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7660
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6491
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.