473,756 Members | 1,808 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 8210
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
1853
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
3680
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
10572
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
3531
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
2791
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
3312
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
7905
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
2435
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
3121
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
9456
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
9275
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,...
1
9843
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
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
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.