Michdd Posted November 30, 2008 Share Posted November 30, 2008 I need help making something that will check if a number (Set in a variable) is within 5 numbers + or - of another number. What would the if statement for this look like? Link to comment https://forums.phpfreaks.com/topic/134829-checking-if-a-number-is-within-a-certain-range-of-other-another/ Share on other sites More sharing options...
cooldude832 Posted November 30, 2008 Share Posted November 30, 2008 try <?php $number = 5 $check_against = 15; $range = 5; $low_range = $range*-1; $v = $number-$check_against; if($v <=$range && $v >=$low_range){ #its good } else{ #outta range } ?> Link to comment https://forums.phpfreaks.com/topic/134829-checking-if-a-number-is-within-a-certain-range-of-other-another/#findComment-702099 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.