With the following script I am able to calculate the frequency of every number from 10 different arrays, then echoes the result sorting the numbers in frequency classes (ex. values that appear one time : x, y, z , values that appear two times : a, b, c, ....etc.)
<?php $set1 = ['23', '11', '52', '33', '1', '4'];
$set2 = ['66', '70', '55', '8', '22', '1'];
$set3 = ['38', '21', '52', '51', '53', '9'];
$set4 = ['14', '31', '54', '5', '73', '39'];
$set5 = ['10', '3', '22', '59', '73', '39'];
$set6 = ['22', '13', '4', '5', '73', '39']
$set7 = ['40', '3', '22', '5', '13', '30'];
$set8 = ['88', '53', '4', '25', '71', '19'];
$set9 = ['10', '30', '49', '25', '73', '46'];
$set10 = ['10', '3', '4', '5', '73', '11'];
$mergedArray = array_merge($set1, $set2, $set3, $set4, $set5, $set6, $set7, $set8, $set9, $set10);
echo 'Values that appear 1 time: ' . implode(', ', array_keys(getRepeatedNumber($mergedArray, 1))) . '<br>';
echo 'Values that appear 2 times: ' . implode(', ', array_keys(getRepeatedNumber($mergedArray, 2))) . '<br>';
echo 'Values that appear 3 times: ' . implode(', ', array_keys(getRepeatedNumber($mergedArray, 3))) . '<br>';
echo 'Values that appear 4 times: ' . implode(', ', array_keys(getRepeatedNumber($mergedArray, 4))) . '<br>';
echo 'Values that appear 5 times: ' . implode(', ', array_keys(getRepeatedNumber($mergedArray, 5))) . '<br>';
function getRepeatedNumber($mergedArray, $requiredCount)
{
$counts = array_count_values($mergedArray);
$requiredResult = array_filter($counts, function ($value) use ($requiredCount) {
return $value == $requiredCount;
});
return $requiredResult;}
My problem : I would like to calculate the frequency and echo the result of an extra array of numbers that should be compared with the actual set of arrays of my script.
For example : If I have
$extraset = ['1', '4', '52'] ;
i would like to
- check how many times those numbers appear in the $set1 to $set10 arrays
- echo the result sorting the numbers in frequency classes like now.
but I don't understand how to compare the $extraset (i am a real newbie..!)
thanks for your help !