I'm trying to write a function that can calculate revenue at different tiered levels... For example you sell $10000 worth of widgets. Any earnings from $1 - $999 we take 50%, $1000 - $4999 we take 25%, $5000 - $9999 we take 10%, $10000 - $19999 5%.
The percentage is not taken based on the final value. So if you earned $10000 you don't just fall into the 10% column. Your first $1000 is subject to 50%, the next $5000 25%, the next $4000 10%.
Thanks in advance.
**Final working code. Thanks for the help!
$input = 10000;
$tiers = array('1000' => .5, '5000' => .25, '10000' => .1, '20000' => .05, '22000' => .01);
$accounted_for = 0;
$total_share = 0;
$tier = each($tiers);
while($accounted_for < $input) {
$cutoff = $tier[0];
$percent = $tier[1];
$level = (min($cutoff, $input) - $accounted_for) * $percent;
$total_share += $level;
$accounted_for = $cutoff;
$tier = each($tiers);
}
return $total_share;