Created
August 16, 2012 18:50
-
-
Save tonylegrone/3372602 to your computer and use it in GitHub Desktop.
Limits an integer within the provided range.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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