I have one big array and I want to make it unique on doc_id and merge roleid
Array
(
[0] => stdClass Object
(
[title] => Test ÆØÅ
[doc_id] => 279
[mid] =>
[type] => 3
[label] =>
[roleid] => 76, 276
)
[1] => stdClass Object
(
[title] => Test ÆØÅ
[doc_id] => 279
[mid] =>
[type] => 3
[label] =>
[roleid] => 76, 276
)
[2] => stdClass Object
(
[title] => NVD AS
[doc_id] => 415
[mid] =>
[type] => 3
[label] =>
[roleid] => 2
)
[3] => stdClass Object
(
[title] => NVD AS
[doc_id] => 415
[mid] =>
[type] => 3
[label] =>
[roleid] => 76, 276
)
[4] => stdClass Object
(
[title] => Test for SN
[doc_id] => 506
[mid] =>
[type] => 3
[label] =>
[roleid] => 76, 276
)
[5] => stdClass Object
(
[title] => Test for SN
[doc_id] => 506
[mid] =>
[type] => 3
[label] =>
[roleid] => 6
)
Just to make it unique I am using below code
foreach ($arry as $val) {
$newArr[$arry ->doc_id] = $val;
}
$result = array_values($newArr);
I am able to get unique document but I lost roleid, I need to merge roleid with doc_id it should be
Array
(
[0] => stdClass Object
(
[title] => Test ÆØÅ
[doc_id] => 279
[mid] =>
[type] => 3
[label] =>
[roleid] => 76, 276
)
[1] => stdClass Object
(
[title] => NVD AS
[doc_id] => 415
[mid] =>
[type] => 3
[label] =>
[roleid] => 2,76, 276
)
[2] => stdClass Object
(
[title] => Test for SN
[doc_id] => 506
[mid] =>
[type] => 3
[label] =>
[roleid] => 6,76, 276
)
Can anyone help in this
Thanks in advance