Wednesday, July 21, 2010

how we can get number of occurance of a value in an array

#array_search_match($needle, $haystack) returns all the keys of the values that match $needle in $haystack
function array_search_all($needle, $haystack){
foreach ($haystack as $k=>$v) {
if($haystack[$k]==$needle){
$array[] = $k;
}
}
return ($array);
}

No comments:

Post a Comment