gogles Posted May 13, 2008 Share Posted May 13, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/105439-array_unique-and-my-duplicates/ Share on other sites More sharing options...
sasa Posted May 13, 2008 Share Posted May 13, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/105439-array_unique-and-my-duplicates/#findComment-540179 Share on other sites More sharing options...
Barand Posted May 13, 2008 Share Posted May 13, 2008 What are the four queries? Quote Link to comment https://forums.phpfreaks.com/topic/105439-array_unique-and-my-duplicates/#findComment-540193 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.