Skip to content

Instantly share code, notes, and snippets.

@dgpro
Created September 14, 2016 10:44
Show Gist options
  • Select an option

  • Save dgpro/8805e8976f61180d4b89990d13b5c4b1 to your computer and use it in GitHub Desktop.

Select an option

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
<?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