<?php
function greatestIndexWhereValueLessThan($haystack, $needle) {
foreach ($haystack as $key => $value) {
if ($value >= $needle) {
break;
}
}
return $key ?? null;
}
echo greatestIndexWhereValueLessThan([30, 60, 90, 120, 360], 73);
echo "\n";
echo greatestIndexWhereValueLessThan([30, 60, 90, 120, 360], 4);
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- 2
0
preferences:
101.61 ms | 406 KiB | 5 Q