Monday, 12 August 2013

PHP Array removing the duplicate values

PHP Array removing the duplicate values

My relationships table looks like this:
`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);
I would like to display partner only once. I trie to do so:
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);
But it doesn't work, nothing happens. What should I do?

No comments:

Post a Comment