Jump to content

Combining two arrays, sort of...


ecopetition

Recommended Posts

Hey,

 

I have the following two arrays, of which I want to use bits of each from to get another array.

Array 1:

Array
(
    [0] => Array
        (
            [shop_id] => 1
            [shop_name] => Aldi
            [shop_district] => 6
        )

    [1] => Array
        (
            [shop_id] => 2
            [shop_name] => Greggs
            [shop_district] => 6
        )

    [2] => Array
        (
            [shop_id] => 3
            [shop_name] => Tesco
            [shop_district] => 6
        )

    [3] => Array
        (
            [shop_id] => 4
            [shop_name] => Morrisons
            [shop_district] => 6
        )

    [4] => Array
        (
            [shop_id] => 5
            [shop_name] => Ryman
            [shop_district] => 6
        )

    [5] => Array
        (
            [shop_id] => 6
            [shop_name] => Boots
            [shop_district] => 6
        )

    [6] => Array
        (
            [shop_id] => 7
            [shop_name] => Superdrug
            [shop_district] => 6
        )

    [7] => Array
        (
            [shop_id] => 8
            [shop_name] => City
            [shop_district] => 2
        )

    [8] => Array
        (
            [shop_id] => 9
            [shop_name] => Lizard
            [shop_district] => 6
        )

    [9] => Array
        (
            [shop_id] => 10
            [shop_name] => Asda
            [shop_district] => 8
        )

    [10] => Array
        (
            [shop_id] => 11
            [shop_name] => Tesco
            [shop_district] => 2
        )

    [11] => Array
        (
            [shop_id] => 12
            [shop_name] => Tesco
            [shop_district] => 8
        )

)

Array
(
    [0] => Array
        (
            [shop_id] => 1
            [shop_name] => Aldi
            [shop_district] => 6
        )

    [1] => Array
        (
            [shop_id] => 2
            [shop_name] => Greggs
            [shop_district] => 6
        )

    [2] => Array
        (
            [shop_id] => 3
            [shop_name] => Tesco
            [shop_district] => 6
        )

    [3] => Array
        (
            [shop_id] => 4
            [shop_name] => Morrisons
            [shop_district] => 6
        )

    [4] => Array
        (
            [shop_id] => 5
            [shop_name] => Ryman
            [shop_district] => 6
        )

    [5] => Array
        (
            [shop_id] => 6
            [shop_name] => Boots
            [shop_district] => 6
        )

    [6] => Array
        (
            [shop_id] => 7
            [shop_name] => Superdrug
            [shop_district] => 6
        )

    [7] => Array
        (
            [shop_id] => 8
            [shop_name] => City
            [shop_district] => 2
        )

    [8] => Array
        (
            [shop_id] => 9
            [shop_name] => Lizard
            [shop_district] => 6
        )

    [9] => Array
        (
            [shop_id] => 10
            [shop_name] => Asda
            [shop_district] => 8
        )

    [10] => Array
        (
            [shop_id] => 11
            [shop_name] => Tesco
            [shop_district] => 2
        )

    [11] => Array
        (
            [shop_id] => 12
            [shop_name] => Tesco
            [shop_district] => 8
        )

)

Array 2:

Array
(
    [0] => Array
        (
            [sUM(item_price)] => 31.23
            [item_shop] => 1
        )

    [1] => Array
        (
            [sUM(item_price)] => 1.65
            [item_shop] => 2
        )

    [2] => Array
        (
            [sUM(item_price)] => 41.23
            [item_shop] => 3
        )

    [3] => Array
        (
            [sUM(item_price)] => 7.98
            [item_shop] => 4
        )

    [4] => Array
        (
            [sUM(item_price)] => 4.49
            [item_shop] => 7
        )

)

 

I'd love if anyone could tell me how I can generate an array that will combine bits of these two arrays, so that using the first array I can get a shop_name and shop_district for each item_shop (aka shop_id).  Then I want to get an array with entries that look something like this:

    [0] => Array
        (
            [sUM(item_price)] => 31.23
            [shop_name] => Aldi
            [shop_district] => 6
        )

 

Thanks so much for your help, it means a lot to me.

Link to comment
https://forums.phpfreaks.com/topic/212923-combining-two-arrays-sort-of/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.