Jump to content

array_unique and my duplicates


gogles

Recommended Posts

I have a problem with the array_unique function.

 

Without the array_unique function the results are:

 

jessica alba and natalya are friends. 2008-05-13

jessica alba and lars ulrich are friends. 2008-05-13

jessica alba and natalya are friends. 2008-05-13

jessica alba and lars ulrich are friends. 2008-05-13

 

And with the array_unique function:

 

jessica alba and natalya are friends. 2008-05-13

 

The desired result would be.

 

jessica alba and natalya are friends. 2008-05-13

jessica alba and lars ulrich are friends. 2008-05-13

 

Any ideas on how could achieve this result?

 

$actions = array();

 

  while ($row = mysql_fetch_array($result_1)) {   

    $actions[] = array("name" => $row["m_name"],

  "name2" => $row["m2_name"],  

    "date" => $row["epoch"]);

  }

 

  while ($row = mysql_fetch_array($result_2)) {

    $actions[] = array("name" => $row["m_name"],

  "name2" => $row["m2_name"],  

    "date" => $row["epoch"]);

  }

  while ($row = mysql_fetch_array($result_3)) {

    $actions[] = array("name" => $row["m_name"],

  "name2" => $row["m2_name"],  

    "date" => $row["epoch"]);

  }

  while ($row = mysql_fetch_array($result_4)) {

    $actions[] = array("name" => $row["m_name"],

  "name2" => $row["m2_name"],  

    "date" => $row["epoch"]);

  }

 

  $actions = array_unique($actions); 

Link to comment
Share on other sites

try to custom function

function my_unique($array){
$k = array_keys($array);
$r = array();
for ($i = 0; $i < count($k) - 1; $i++){
	for ($j = $i + 1; $j < count($k); $j++){
		if ($array[$k[$i]] == $array[$k[$j]]) $r[] = $j;
	}
}
$r = array_unique($r);
foreach ($r as $k) unset($array[$k]);
return $array;
}

$actions = my_unique($actions);

Link to comment
Share on other sites

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.