PHP数组删除重复的值

时间:2013-08-12 16:57:04

标签: php arrays double

我的人际关系表如下:

`relationships` (`relationship_id`, `relationship_individual`, `parent_id`, `partner_id`) VALUES
(28, 160, 161, NULL),
(29, 161, 163, 162),
(30, 162, NULL, 161),
(31, 163, NULL, 164),
(32, 164, NULL, 163),
(34, 166, NULL, 165),
(36, 165, NULL, 166);

我想只展示一次合作伙伴。我想这样做:

foreach($tree as $child) {
    foreach($tree as $c) {
        if($child['relationship_individual'] != $c['relationship_individual'] && $child['partner_id'] == $c['relationship_individual']){
        unset($tree[$child['partner_id']]);
        }
    }
}
print_r($tree);

但它不起作用,没有任何反应。我该怎么办?

1 个答案:

答案 0 :(得分:0)

您可以保留重复项,但在获取它们时,您可能希望执行DISTINCT MySQL查询。

MySQL DISTINCT Help