Jump to content

Removing duplicate values in multidimensional array HELP!


brendz

Recommended Posts

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 :)!

 

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);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.