$discounts = array(
1000 => 5,
1500 => 10,
2000 => 15,
);
function getDiscountPercent($sum, $discounts) {
for ($discount_percent = 0, reset($discounts); current($discounts) && $sum >= key($discounts); next($discounts)) {
$discount_percent = current($discounts);
}
return $discount_percent;
}