$counter = $i + 1; while ($forest[$current][$counter] < $forest[$current][$i] and $found == 0) { $counter += 1; if ($counter == 99) { $visible += 1; $found = 1; $counter = 1; } }