I came up with a simple solution while working on a personal project.
Since I wanted some sort of duplicated keys, I decided to store my array key=>values in a reverse order value=>key where value becomes the key and the key becomes the value, this way I could have duplicate keys which in fact are values. I am not creating duplicated values so it works in this specific case.
So a little example:
$r = array ( 'banana'=>'FRUIT', 'apple'=>'FRUIT', 'broccoli'=>'VEG', 'peas'=>'VEG' );
function get_food_group ( $type, $bowl ) {
return array_keys ( $bowl, $type );
}
print_r ( get_food_group('FRUIT', $r) );
# PRINTS #
# Array
# (
# [0] => banana
# [1] => apple
# )
If you're gonna have something like:
array (
'banana' => 'FRUIT',
'peach' => 'FRUIT',
'banana' => 'YELLOW'
)
Then I would go with another solution.