I need to find a way to make a function that when a number is entered it would round UP ONLY to the nearest number in an array I SPECIFY.
id have 40,70,140,200
someone enters 110 so it selects 140
Any ideas?
Untested:
$numbers = array(200, 140, 70, 40); // need to be in descending order $test = 110; foreach($numbers as $value) { if ($test <= $value) { $rounded = $value; break; } }
Unfortunatly that will always choose 200 regardless of the number entered. (if its under 200 obviously) which it will always be under 200
Maybe switching to Ascending order will fix that?
Yeah, for some reason it made sense at the time. Try inverting the array order and see if that works (or just invert the comparison operator).
Reversing the array worked just fine. THANKS you prolly saved me atleast 2 hours of going DUUH 😛