from URL : Count number of a group array in array in php
I ask question :
$arr1 = [61,41,41,61,89,90]
$arr2 = [61,41]
$result = 2
//found 61 and 41 in $arr1 2 time;
//This mean : found 61 and 41 in $arr1[0] and $arr1[1]
//and found 61 and 41 in $arr1[3] and $arr1[2] again
//So $result = 2
I follow the answer. That is code:
$arr1 = array(61,41,41,61,89,90);
$arr2 = array(61,41);
$count = array_count_values($arr1); //count values from arr1
$result = array();
foreach($arr2 as $row) {
$result[$row] = array_key_exists($row, $count) ? $count[$row] : 0;
}
echo min($result);
But It have a bug. If I assume
$arr1 = array(5,6,5,6,5,7);
$arr2 = array(5,5);
$result = 1;
//This mean : found 5 and 5 in $arr[0] and $arr[2]
// but is'not found 5 and 5 again
That true result is 1. but this result is 3. Please help me to fix this bug.