unique - PHP: Function to group array of objects by value -
i working multi-dimensional array. how can remove duplicates value? in following array, [0], [2] , [5] have same [id]. there function remove duplicate arrays based on particular value? in case, remove array [2] , array [5], have same [id] array [0].
thank information may have.
array ( [0] => stdclass object ( [d] => 2010-10-18 03:30:04 [id] => 9 ) [1] => stdclass object ( [d] => 2010-10-18 03:30:20 [id] => 4 ) [2] => stdclass object ( [d] => 2010-11-03 16:46:34 [id] => 9 ) [3] => stdclass object ( [d] => 2010-11-02 03:19:14 [id] => 1 ) [4] => stdclass object ( [d] => 2010-05-12 04:57:34 [id] => 2 ) [5] => stdclass object ( [d] => 2010-05-10 05:24:15 [id] => 9 ) )
one way it: ($old_array
array, , $new_array
contain new one, dupes removed, keyed id)
$new_array = array(); foreach ($old_array $item) if (!array_key_exists($item->id, $new_array)) $new_array[$item->id] = $item;
(i haven't tested this, should work)
Comments
Post a Comment