Hi,
I wonder if there is another simpler solution to my problem. Ok I'm trying to pass the following array:
Array ( [0] => Cadence Healthcare, Montreal, Canada [1] => Cadence Healthcare, Montreal, Canada [2] => Pfizer, Montreal, Canada [3] => Pfizer, Montreal, Canada )
to these two functions:
This function checks $array for duplicate values and returns an array containing the keys of duplicates
function unique_events($array){
$count= array_key_intersect($array, array_flip(array_count_values($array)));
foreach($array as $key=>$value)
{
if (in_array($value,$count))
{
$return[$value][]=$key;
}
}
return $return;
}
function array_key_intersect(&$a, &$b) {
$array = array();
while (list($key,$value) = each($a)) {
if (isset($b[$key]))
$array[$key] = $value;
}
return $array;
}
Here is the result of what function unique_events returns:
Array ( [Pfizer, Montreal, Canada] => Array ( [0] => 2 [1] => 3 ) )
What I'm trying to obtain is:
Array ( [Cadence Healthcare, Montreal, Canada] => Array ( [0] => 0 [1] => 1)[Pfizer, Montreal, Canada] => Array ( [0] => 2 [1] => 3 ) )
If also I try a different combination in my array, say for example this:
Array ( [0] => Cadence Healthcare, Montreal, Canada [1] => Merck, Montreal, Canada [2] => Pfizer, Montreal, Canada )
I get the following:
Array ( [Merck, Montreal, Canada] => Array ( [0] => 1 ) )
What I'm trying to obtain is:
Array ( [Cadence Healthcare, Montreal, Canada] => Array ( [0] => 0 ) [Merck, Montreal, Canada] => Array ( [0] => 1 [Pfizer, Montreal, Canada] => Array ( [0] => 2 )) )
Something is probably duplicated or skipped and i'm not sure why is that...There has to be a workaround to this? Anyone? 🙁