Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging an Array and an Object

Status
Not open for further replies.

Geee

Programmer
Apr 23, 2001
253
GB
I have an array of data that contains a key [id], and also a list of extended information relating to the data stored in an object that contains the key [chanid]. What I would like to do is loop through one or the other and output all the information from both data sources. The only way I can think to do it is to iterate through one and then the other which I would imagine would be hidiously bloated!

The data is as follows:

Code:
Array one, contains details of available TV channels:

 [0] => Array
        (
            [id] => 22
            [name] => BBC ONE WALES
            [port] => 1252
            [mplexid] => 14
            [channum] => 1
        )

    [1] => Array
        (
            [id] => 23
            [name] => BBC 2W
            [port] => 1253
            [mplexid] => 14
            [channum] => 2
        )

    [2] => Array
        (
            [id] => 28
            [name] => ITV1 WALES
            [port] => 1258
            [mplexid] => 15
            [channum] => 3
        )

    [3] => Array
        (
            [id] => 42
            [name] => S4/C
            [port] => 1272
            [mplexid] => 16
            [channum] => 4
        )

    [4] => Array
        (
            [id] => 44
            [name] => FIVE
            [port] => 1274
            [mplexid] => 16
            [channum] => 5
        )

    [5] => Array
        (
            [id] => 29
            [name] => ITV2
            [port] => 1259
            [mplexid] => 15
            [channum] => 6
        )



Object two, contains more information from a SOAP source:

 [0] => stdClass Object
        (
            [id] => 130152
            [chanid] => 84
            [starttime] => 1217329200
            [endtime] => 1217331000
            [title] => Judge Judy
            [subtitle] => 
            [description] => New York City's outspoken family court judge Judy Sheindlin presides over a series of real-life cases and conflicts, trying to find solutions for all kinds of family issues. [S]
            [category] => 
            [airdate] => 
            [previouslyshown] => 
            [seriesid] => 
        )

    [1] => stdClass Object
        (
            [id] => 130151
            [chanid] => 84
            [starttime] => 1217331000
            [endtime] => 1217332800
            [title] => Judge Judy
            [subtitle] => 
            [description] => New York City's outspoken family court judge Judy Sheindlin presides over a series of real-life cases and conflicts, trying to find solutions for all kinds of family issues. [S]
            [category] => 
            [airdate] => 
            [previouslyshown] => 
            [seriesid] => 
        )

    [2] => stdClass Object
        (
            [id] => 130177
            [chanid] => 87
            [starttime] => 1217318400
            [endtime] => 1217332800
            [title] => Angie Greaves
            [subtitle] => 
            [description] => More music, less talk for your afternoon.
            [category] => 
            [airdate] => 
            [previouslyshown] => 
            [seriesid] => 
        )

    [3] => stdClass Object
        (
            [id] => 130181
            [chanid] => 87
            [starttime] => 1217332800
            [endtime] => 1217347200
            [title] => Paul Phear
            [subtitle] => 
            [description] => More music, less talk for your afternoon.
            [category] => 
            [airdate] => 
            [previouslyshown] => 
            [seriesid] => 
        )

    [4] => stdClass Object
        (
            [id] => 130184
            [chanid] => 88
            [starttime] => 1217322000
            [endtime] => 1217332800
            [title] => Vicky Warham
            [subtitle] => 
            [description] => Vicky has the biggest hits around for your morning, along with the latest national news and showbiz stories every hour on Inside The Hits.
            [category] => 
            [airdate] => 
            [previouslyshown] => 
            [seriesid] => 
        )

    [5] => stdClass Object
        (
            [id] => 130188
            [chanid] => 88
            [starttime] => 1217332800
            [endtime] => 1217343600
            [title] => Mark Kaye
            [subtitle] => 
            [description] => Mark has the biggest tunes around for your afternoon ahead of You Call The Hits at 4pm, get your call in early now to 08444 15 81 81 [local rate from landline].
            [category] => 
            [airdate] => 
            [previouslyshown] => 
            [seriesid] => 
        )


The 2 arrays are linked where [id] in array one is equal to [chanid] in the object 2, I am looking for a way to merge to two into one array, or possible reference the object by the id got from array 1. Effectively I am trying to avoid multiple iteration!

All suggestions greatfully received!!!

-Geeeeeeeeeeeeeeeeeeeeeeee-
 
hav you looked at get_object_vars() and array_merge(). looks like you might get those to work for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top