php - If quantity is 6 or multiple of 6 so 1% discount
Get the solution ↓↓↓Solution:
All you need is magic.
$magicPriceFunction = function ($pricePerItem, $itemCount) {
$magicNumber = 6;
$discount = 0.1;
$unhappyItemCount = $itemCount % $magicNumber;
$total = 0;
$total += $pricePerItem * $unhappyItemCount;
$total += ($itemCount - $unhappyItemCount) * (1 - $discount) * $pricePerItem;
return $total;
};
var_dump($magicPriceFunction(100, 6));
Answer
Solution:
I guess this is one way you could do it
$quantity = 8;
$remainder = $quantity % 6 ? $quantity % 6 : 0;
$discountItems = $quantity - $remainder;
echo "10% off " . $discountItems . " items and full price on " . $remainder;
// 10% off 6 items and full price on 2
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: zsh: command not found: php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.