Skip to content

Instantly share code, notes, and snippets.

@jveldboom
Created March 5, 2013 17:23
Show Gist options
  • Save jveldboom/5092072 to your computer and use it in GitHub Desktop.
Save jveldboom/5092072 to your computer and use it in GitHub Desktop.
Spread amount over a quantity. Uses a balancer amount to last item
<?php
function spreadAmount($amount,$qty)
{
if($amount % $qty === 0)
{
$start = $amount / $qty;
$last = $start;
}
else
{
$start = round(($amount / $qty) * 100) / 100;
$last = $amount - ($start * ($qty - 1));
}
for($x=0;$x<$qty-1;$x++){
$return[] = $start;
}
$return[] = $last;
return $return;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment