I was trying to use array_search to retrieve all the values that match a given needle, but it turns out only the first match key is returned. I built this little function, which works just like array_search, but returns all the keys that match a given needle instead. The output is an array.
<?php
$haystack = array('a','b','a','b');
$needle = 'a';
print_r(array_search_all($needle, $haystack));
function array_search_all($needle, $haystack)
{foreach ($haystack as $k=>$v) {
if($haystack[$k]==$needle){
$array[] = $k;
}
}
return ($array);
}
?>