I wrote a function to "clamp" numbers in PHP, but I wonder if this function exists natively in the language.
I read PHP.net documentation in the math section, but I couldn't find it.
Basically what my function does is that it accepts a variable, an array of possible values, and a default value, this is my function's signature:
function clamp_number($value, $possible_values, $default_value)
If $value
does not match any of the $possible_values
then it defaults to $default_value
I think my function would be way faster if PHP already provides it natively because I'm using quite often in my program.
filter_var
), nope, no built in. To determine wether we can speed up your custom function we'd need to see it. – Merilynmeringue