Merge 2 arrays based on shared value


#1

I have one array, called for example $MainImages : -

[code]Array
(
[0] => Array
(
[uniqueID] => 143
[image] => image_a.jpg
)

[1] => Array
    (
        [uniqueID] => 147
        [image] => image_b.jpg
    )

[2] => Array
    (
        [uniqueID] => 73
        [image] => image_c.jpg
    )

)[/code]

and a second array, we’ll call it $widgets: -

[code]Array
(
[0] => Array
(
[uniqueID] => 147
[seo_title] => An excellent class B Widget
[name] => Widget B
[categoryID] => 1
)

[1] => Array
    (
        [uniqueID] => 73
        [seo_title] => An excellent class C Widget
        [name] => Widget C
        [categoryID] => 1
    )

[2] => Array
    (
        [uniqueID] => 143
        [seo_title] => An excellent class A Widget
        [name] => Widget A
        [categoryID] => 1
    )

)[/code]

I want to merge the value from the [][image] key from the first array into a new [][image] key / value in the second, using a shared value as a reference…so the desired result array is: -

[code]Array
(
[0] => Array
(
[uniqueID] => 147
[seo_title] => An excellent class B Widget
[name] => Widget B
[categoryID] => 1
[image] => image_b.jpg
)

[1] => Array
    (
        [uniqueID] => 73
        [seo_title] => An excellent class C Widget
        [name] => Widget C
        [categoryID] => 1
        [image] => image_c.jpg
    )

[2] => Array
    (
        [uniqueID] => 143
        [seo_title] => An excellent class A Widget
        [name] => Widget A
        [categoryID] => 1
        [image] => image_a.jpg
    )

)[/code]

Obviously the order is different and so they need to be merged based on the UniquID values.

I’ve looked at a lot of help but can’t find anything to do exactly what I need…any help would be greatly appreciated!


#2

I should have said, although I’ve used [uniqueID] the same ID may be in each array more than once.