Jump to content

Array Merge or Consolidate


peterg0123

Recommended Posts

Hi,

 

Have a question regarding array handling / changes.  I have the below posted array.  I need to consolidation the "categoryId" & "categoryName" where the "id" have the same value e.g. 66, then remove the duplicates but keep the merged data.  The new merged data could be stored under a key e.g.

 

[categories] => Array (

[0]

    [categoryId] = 28

    [categoryName] = Game Drive

[1]

      [categoryId] = 29

      [categoryName] = Game Drive

 

etc.

 

 

 

Array
(
    [0] => Array
        (
            [id] => 66
            [name] => Person Name
            [description] => Test Desc
            [webUrl] => www.nish.co.za
            [emailAddress] => abc@abc.co.za
            [telNumber] => 123123
            [provinceId] => 3
            [cityId] => 2
            [creationDate] => 2010-09-27 17:42:55
            [activated] => Y
            [categoryId] => 28
            [provinceName] => Gauteng
            [cityName] => Johannesburg
            [categoryName] => Game Drives
        )

    [1] => Array
        (
            [id] => 66
            [name] => Person Name
            [description] => Test Desc
            [webUrl] => www.nish.co.za
            [emailAddress] => abc@abc.co.za
            [telNumber] => 123123
            [provinceId] => 3
            [cityId] => 2
            [creationDate] => 2010-09-27 17:42:55
            [activated] => Y
            [categoryId] => 29
            [provinceName] => Gauteng
            [cityName] => Johannesburg
            [categoryName] => Nature Reserve
        )

    [2] => Array
        (
            [id] => 66
            [name] => Person Name
            [description] => Test Desc
            [webUrl] => www.nish.co.za
            [emailAddress] => abc@abc.co.za
            [telNumber] => 123123
            [provinceId] => 3
            [cityId] => 2
            [creationDate] => 2010-09-27 17:42:55
            [activated] => Y
            [categoryId] => 34
            [provinceName] => Gauteng
            [cityName] => Johannesburg
            [categoryName] => Rehabilitation Centre
        )

    [3] => Array
        (
            [id] => 65
            [name] => Person Name
            [description] => This is the true test
            [webUrl] => http://www.klil.com
            [emailAddress] => abc@abc.co.za
            [telNumber] => 12311231
            [provinceId] => 3
            [cityId] => 2
            [creationDate] => 2010-09-26 19:33:14
            [activated] => Y
            [categoryId] => 28
            [provinceName] => Gauteng
            [cityName] => Johannesburg
            [categoryName] => Game Drives
        )

    [4] => Array
        (
            [id] => 65
            [name] => Test Multiple Categ
            [description] => This is the true test
            [webUrl] => http://www.klil.com
            [emailAddress] => abc@abc.co.za
            [telNumber] => 12311231
            [provinceId] => 3
            [cityId] => 2
            [creationDate] => 2010-09-26 19:33:14
            [activated] => Y
            [categoryId] => 29
            [provinceName] => Gauteng
            [cityName] => Johannesburg
            [categoryName] => Nature Reserve
        )

    [5] => Array
        (
            [id] => 65
            [name] => Person Name
            [description] => Description Text
            [webUrl] => http://www.test.com
            [emailAddress] => abc@abc.co.za
            [telNumber] => 12311231
            [provinceId] => 3
            [cityId] => 2
            [creationDate] => 2010-09-26 19:33:14
            [activated] => Y
            [categoryId] => 34
            [provinceName] => Gauteng
            [cityName] => Johannesburg
            [categoryName] => Rehabilitation Centre
        )

    [6] => Array
        (
            [id] => 64
            [name] => Person Name
            [description] => Description Text
            [webUrl] => www.tree.com
            [emailAddress] => abc@abc.co.za
            [telNumber] => 1123123123
            [provinceId] => 3
            [cityId] => 1
            [creationDate] => 2010-09-26 12:10:56
            [activated] => Y
            [categoryId] => 28
            [provinceName] => Gauteng
            [cityName] => Alexandra
            [categoryName] => Nature Walks
        )

    [7] => Array
        (
            [id] => 64
            [name] => Person Name
            [description] => Description Text
            [webUrl] => www.tree.com
            [emailAddress] => abc@abc.co.za
            [telNumber] => 1123123123
            [provinceId] => 3
            [cityId] => 1
            [creationDate] => 2010-09-26 12:10:56
            [activated] => Y
            [categoryId] => 29
            [provinceName] => Gauteng
            [cityName] => Alexandra
            [categoryName] => Nature Reserve
        )

    [8] => Array
        (
            [id] => 64
            [name] => Person Name
            [description] => Description Text
            [webUrl] => www.tree.com
            [emailAddress] => abc@abc.co.za
            [telNumber] => 1123123123
            [provinceId] => 3
            [cityId] => 1
            [creationDate] => 2010-09-26 12:10:56
            [activated] => Y
            [categoryId] => 34
            [provinceName] => Gauteng
            [cityName] => Alexandra
            [categoryName] => Rehabilitation Centre
        )

    [9] => Array
        (
            [id] => 63
            [name] => Person Name
            [description] => Description Text
            [webUrl] => www.test.com
            [emailAddress] => abc@abc.co.za
            [telNumber] => 123123
            [provinceId] => 5
            [cityId] => 3
            [creationDate] => 2010-09-26 09:58:41
            [activated] => Y
            [categoryId] => 29
            [provinceName] => Limpopo
            [cityName] => Bandelierkop
            [categoryName] => Nature Reserve
        )
)

 

Thanks in advance,

Peter

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.