проверено по следующему сценарию
$ranks = [3,4,3,0,2,2,3,0,0]; // 5
$ranks = [11,10,10,10,10,8,8,7,6,4,4,4,4,4,3,3,3,3,3,1,0]; //12
$ranks = [4, 3,1,0,0,0]; //4
$ranks = [4, 4, 3, 3, 1, 0] ; // 3
$ranks = [4, 2, 0] ; // 0
get_reporting_rank($ranks);
function get_reporting_rank($ranks){
$len = count($ranks);
sort($ranks);
$reporting_soldier = 0;
$i = 0;
$next_superior_reporting = 0;
foreach($ranks as $rank){
$upper = $rank+ 1;
if(in_array ( $upper, $ranks ,TRUE )){
if ($i !== $len) {
$reporting_soldier = $reporting_soldier+1;
}
}
$i++;
}
echo "<h1>Reporting :".$reporting_soldier;
}