PHP array:
$arr = array(0,15,60,120,2200);
I pass a $number = 12
with array value in function, then return value should be 0
and I pass a $number = 15
with array value in function, then return value should be 15
I was trying with below code but not luck
<?php
function get_less_value($arr, $number) {
foreach ($arr as $val) {
if ($val>= $number && $val < $number) return $val;
}
return end($arr);
}
echo get_less_value($arr, $number);
?>