$arr = array(3, 8, 1, 9, 4, 10, 7, 13, 2, 6);
$size = count($arr);
$N = 4;
$just_greater = PHP_INT_MAX;
$just_smaller = PHP_INT_MIN;
for ($i = 0; $i < $size; $i++) {
if ($arr[$i] > $N && $arr[$i] < $just_greater) {
$just_greater = $arr[$i];
}
if ($arr[$i] < $N && $just_smaller < $arr[$i]) {
$just_smaller = $arr[$i];
}
}
echo "just_smaller: " . strval($just_smaller),"\n";
echo "N: " . strval($N),"\n";
echo "just_greater: " . strval($just_greater),"\n";
/*
run:
just_smaller: 3
N: 4
just_greater: 6
*/