brendz Posted January 28, 2009 Share Posted January 28, 2009 Hi, I have this really urgent problem of not being able to remove duplicates values from a multidimensional array, I have a array with breadcrumbs details and need to loop this and remove all the duplicate values - I can't use array_unique as that only works on a single array. Here is the code i have used - //Array called items! $count = count($items); for ($i = 0; $i < $count; $i ++) { $items[$i]->name = stripslashes(htmlspecialchars($items[$i]->name)); $items[$i]->link = JRoute::_($items[$i]->link); } //Inside the loop need to check the $items[$i]->name for the duplicate values but also mind to remove the corresponding link items as well. Its's a joomla breadcrumb which I'm try to fix. Any ideas would be a big help as the boss is breathing down my neck to stop spending so much time on this ! Link to comment https://forums.phpfreaks.com/topic/142867-removing-duplicate-values-in-multidimensional-array-help/ Share on other sites More sharing options...
sasa Posted January 28, 2009 Share Posted January 28, 2009 try <?php function remove_duplicate($items){ $count = count($items); $names = array(); $items1 = array(); for ($i = 0; $i < $count; $i ++) { if (!in_array($items[$i]->name, $names)){ $names[] = $items[$i]->name; $items1[] = $items[$i]; } } return $items1; } $items = remove_duplicate($items); ?> Link to comment https://forums.phpfreaks.com/topic/142867-removing-duplicate-values-in-multidimensional-array-help/#findComment-748983 Share on other sites More sharing options...
brendz Posted January 28, 2009 Author Share Posted January 28, 2009 oh my god its working straight away! I spend 6 hours on this today try to work this out! You are amazing thanks mate! Link to comment https://forums.phpfreaks.com/topic/142867-removing-duplicate-values-in-multidimensional-array-help/#findComment-749001 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.