I have array data from two separate mysql queries. Array data looks like below:
0
:
{user_id: 82, ac_type: 1,…}
1
:
{user_id: 80, ac_type: 5,…}
2
:
{user_id: 76, ac_type: 1,…}
3
:
{user_id: 82, ac_type: 1,…}
4
:
{user_id: 80, ac_type: 5,…}
I want to remove the duplicate array items.
So, my output will be like this:
0
:
{user_id: 82, ac_type: 1,…}
1
:
{user_id: 80, ac_type: 5,…}
2
:
{user_id: 76, ac_type: 1,…}
I want to check duplicate by user_id.
I have tried the following solutions, but neither are not working as desired.
$input = array_unique($res, SORT_REGULAR);
$input = array_map("unserialize", array_unique(array_map("serialize", $res)));
I also tried below.
$results = array();
foreach ($res as $k => $v) {
$results[implode($v)] = $v;
}
$results = array_values($results);
print_r($results);
But still duplicate data exist.
See Question&Answers more detail:os