PHP merge multidimensional array if certain values are duplicate
I have the following PHP multidimensional array. I'd like to somehow go
though the array and see if any have 3 matching criteria and if so,
combine those into one. Any fields that are unique would use the info from
the first in the array. So in the example below, I'd like to look for
[action], [on] and [media][id]. If all three match, they would be combined
into one. However, I'd like to be able to have a count of the original
before the merge, and keep track of the [seen] values too. In the example
below I show what the original would look like, followed by the finished
array. I would really appreciate any help on this.
ORIGINAL LIKE THIS:
[0] => Array //HAS DUPLICATE
(
[action] => like
[seen] => false
[on] => photos
[from_user_id] => 2
[media] => Array
(
[id] => 3688
[path] => f2892213.jpg
[med_type] => pic
)
)
[1] => Array //HAS DUPLICATE
(
[action] => like
[seen] => true
[on] => photos
[from_user_id] => 13
[media] => Array
(
[id] => 3688
[path] => f2892213.jpg
[med_type] => pic
)
)
[2] => Array
(
[action] => like
[seen] => false
[on] => photos
[from_user_id] => 21
[media] => Array
(
[id] => 6372
[path] => H9384yhds
[med_type] => vid
)
)
[3] => Array //HAS DUPLICATE
(
[action] => like
[seen] => false
[on] => photos
[from_user_id] => 11
[media] => Array
(
[id] => 3688
[path] => f2892213.jpg
[med_type] => pic
)
)
FINISHED ARRAY SOMETHING LIKE THIS:
[0] => Array
(
[action] => like
[on] => photos
[from_user_id] => 2
[media] => Array
(
[id] => 3688
[path] => f2892213.jpg
[med_type] => pic
)
[count_before_merge] => 3
[seen_before_merge] => 1
)
[1] => Array
(
[action] => like
[seen] => false
[on] => photos
[from_user_id] => 21
[media] => Array
(
[id] => 6372
[path] => H9384yhds
[med_type] => vid
)
)
No comments:
Post a Comment