嘗試這樣:
<?php
//array to store the number of matches
$matchesArr = array(0,0,0,0,0,0,0);
//your lottery numbers
$myNumbers = array(1,2,3,4,5,6);
//the past lottery results
$pastResults = array(
array(10,12,1,2,34,11),
array(10,12,1,2,34,11),
array(10,12,1,2,34,11)
);
//loop through each past lottery result
foreach($pastResult as $pastResult){
$matches = 0;
//do any of your numbers appear in this result?
foreach($myNumbers as $myNumber){
if(in_array($myNumber, $pastResult)){
$matches++;
}
}
//add the number of matches to the array
$matchesArr[$matches]++;
}
//print the number of matches
foreach($matchesArr as $index=>$matches){
echo $index." number = ".$matches."\n";
}
?>
http://stackoverflow.com/questions/13633954/how-do-i-count-occurrence-of-duplicate-items-in-array –