Jump to content

Removing duplicate values in multidimensional array HELP!


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.