I\'m trying to use array_flip
to print duplicate values in a comma separated format
$a=array(\"a\"=>\"red\",\"b\"=>\"green\",\"c\"=>\"b
array_flip
will not give your expected output. Instead of this you can write your custom function like:
$a=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"blue");
$flip = array_flip_custom($a);
print_r($flip);
function array_flip_custom($a){
$flip = array();
foreach($a as $index=>$key){
if($flip[$key]){
$flip[$key] .= ','.$index;
} else {
$flip[$key] = $index;
}
}
return $flip;
}
Will give output:
Array ( [red] => a [green] => b [blue] => c,d )