I would run first on the ranges array ($arr2) and for each of those find how many items from the first array fit. The exact details though really depends on the expected result.
//Comps Esg Grades
$arr1 = [1,2,3,9,5,6,20,35,9,10];
//Final Compare
$arr2 = [0,1.7,10.4,20,30,44,60];
$countArray = [];
for ($i=0; $i<count($arr2)-1; $i++) {
$min = $arr2[$i];
$max = $arr2[$i+1];
$countArray[$i] = 0;
for ($j=0; $j<count($arr1); $j++) {
if ($arr1[$j] >= $min && $arr1[$j] <= $max) {
$countArray[$i]++;
}
}
}
print_r($countArray);
Output:
Array
(
[0] => 1
[1] => 7
[2] => 1
[3] => 1
[4] => 1
[5] => 0
)
solved check And Count Value over php array [closed]