Skip to content

Instantly share code, notes, and snippets.

@tonylegrone
Created August 16, 2012 18:50
Show Gist options
  • Save tonylegrone/3372602 to your computer and use it in GitHub Desktop.
Save tonylegrone/3372602 to your computer and use it in GitHub Desktop.
Limits an integer within the provided range.
<?php
/**
* Limits an integer within the provided range.
*
* @param int $int
* The integer to test against.
* @param int $min_limit
* The minimum number $int allowed to return.
* @param int $max_limit
* The maximum number $int allowed to return.
*
* @return int
* $int if it is within the range of $min_limit and $max_limit.
* If $int is above or below the provided limits, $max_limit or $min_limit
* will be returned respectively.
*/
function int_limiter($int, $min_limit, $max_limit) {
$int = ($int >= $min_limit)? $int:$min_limit;
$int = ($int <= $max_limit)? $int:$max_limit;
return $int;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment