Я пытаюсь получить номер скидки (значение) с предопределенными плитами в виде массива.
Так, например, если общее количество продуктов составляет от 11 до 20, я хочу вернуть 25 в качестве скидкистоимость.
Это может быть просто, но я не понимаю, как это сделать.Как простой цикл foreach, вероятно, не будет работать.
/**
* The function returns the discount amount from the slabs
*
* @param int $products_count total number of product in cart
*
* @return mixed null|int returns discount value if matches else null
*/
public function product_discounts($products_count)
{
$discount_slabs = [
'10' => '15',
'20' => '25',
'30' => '35',
'50' => '50',
];
foreach ($discount_slabs as $count => $discount) {
if ($products_count <= $count) {
$this->discount = $discount;
}
}
return $this->discount;
}