Created
September 14, 2016 10:44
-
-
Save dgpro/8805e8976f61180d4b89990d13b5c4b1 to your computer and use it in GitHub Desktop.
PHP function to get individual product price/fee based on bundle size and total price
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @param int $amount | |
| * @param int $count | |
| */ | |
| function amountFromBundle(int $amount, int $count) | |
| { | |
| $mod = $amount % $count; | |
| $div = ($amount - $mod) / $count; | |
| $a = array_fill(0, $count - $mod, $div); | |
| $a += array_fill($count - $mod, $mod, $div + 1); | |
| reset($a); | |
| return $a; | |
| } | |
| print_r(amountFromBundle(1599, 5)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment