从数组中删除重复项
2022-08-30 16:49:56
我使用下面的代码行来遍历数据库中的表:
$items_thread = $connection -> fetch_all($sql);
如果我打印出阵列:
print_r($items_thread);
我会得到这个:
Array
(
[0] => Array
(
[RecipientID] => 3
[RecipientScreenname] => Tom L
[RecipientFirstname] => Thomas
[RecipientEmail] => info@xx.com
)
[1] => Array
(
[RecipientID] => 3
[RecipientScreenname] => Tom L
[RecipientFirstname] => Thomas
[RecipientEmail] => info@xx.com
)
[2] => Array
(
[RecipientID] => 1
[RecipientScreenname] => Lau T
[RecipientFirstname] => TK
[RecipientEmail] => lau@xx.co.uk
)
)
但是我想摆脱数组中的重复项,所以我使用array_unique
print_r(array_unique($items_thread));
我得到下面的奇怪结果,这不是我正在寻找的:
Array
(
[0] => Array
(
[RecipientID] => 3
[RecipientScreenname] => Tom L
[RecipientFirstname] => Thomas
[RecipientEmail] => info@xx.com
)
)
理想情况下,我认为它应该返回这个:
Array
(
[0] => Array
(
[RecipientID] => 3
[RecipientScreenname] => Tom L
[RecipientFirstname] => Thomas
[RecipientEmail] => info@xx.com
)
[1] => Array
(
[RecipientID] => 1
[RecipientScreenname] => Lau T
[RecipientFirstname] => TK
[RecipientEmail] => lau@xx.co.uk
)
)
我该怎么做才能把它做好?我是否使用了错误的 PHP 语法/默认函数?