Skip to content

Instantly share code, notes, and snippets.

@s3b4stian
Created November 4, 2017 19:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s3b4stian/7f17b1545344ef7cec18b6ac1e6c715f to your computer and use it in GitHub Desktop.
Save s3b4stian/7f17b1545344ef7cec18b6ac1e6c715f to your computer and use it in GitHub Desktop.
/**
* Check if value is between given range.
*
* @param mixed $value
* @param mixed $min
* @param mixed $max
*
* @return bool
*/
function in_range($value, $min, $max): bool {
if ($value >= $min && $value <= $max) {
return true;
}
return false;
}
/**
* Check if value is between given ranges.
*
* @param mixed $value
* @param array $ranges
*
* @return bool
*/
function in_ranges($value, array $ranges): bool {
foreach ($ranges as $range) {
if ($value >= $range[0] && $value <= $range[1]) {
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment