It seems you are just trying to find the number inside the set. The actual clamp function will ensure that the number is within two numbers (lower bounds and upper bounds). Thus, the psudo code will clamp(55, 1, 10) will produce 10 , and clamp(-15, 1, 10) will produce 1 , where clamp(7, 1, 10) will produce 7 . I know that you are looking for more in_array methods, but for those who get here from Google, here is how you can clamp PHP without creating a function (or making it a function).
max($min, min($max, $current))
For instance:
$min = 1; $max = 10; $current = 55; $clamped = max($min, min($max, $current)); // $clamped is now == 10
A simple clamping method would be:
function clamp($current, $min, $max) { return max($min, min($max, $current)); }
source share