472,791 Members | 1,296 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 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 8150
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.