modular function for getting total shipping sizes
<p>A site I'm currently building uses a shipping company that has three different pallet sizes for shipping: up to 250kg, up to 500kg and up to 1000kg.</p>

<p>While I've built a function to get the configuration of pallets needed for the total weight, it is kind of hard coded and I'm looking for a more modular way of working this out if I throw in another pallet weight at a later date or use the same functionality for another project.</p>

<p>What I have is this:</p>

<pre><code>$sizes = array(
        array('desc'=&gt;'large','limit'=&gt;1000),
        array('desc'=&gt;'medium','limit'=&gt;500),
        array('desc'=&gt;'small','limit'=&gt;250)
        );
foreach ($sizes as $k=&gt;$v) {
    $pallets[$v['desc']] = 0;
}

echo $total_weight = 2280;
echo "&lt;hr /&gt;";

function pallet_size($weight) {

    global $sizes, $pallets;

    if ($weight &gt; $sizes[1]['limit']) {
        $pallets[$sizes[0]['desc']]+=1;
        $weight-=$sizes[0]['limit'];
        pallet_size($weight);
    } elseif ($weight &gt; $sizes[2]['limit']) {
        $pallets[$sizes[1]['desc']]+=1;
        $weight-=$sizes[1]['limit'];
        pallet_size($weight);
    } elseif ($weight &lt; $sizes[2]['limit'] &amp;&amp; $weight&gt;0) {
        $pallets[$sizes[2]['desc']]+=1;
        $weight-=$sizes[2]['limit'];
        pallet_size($weight);
    } elseif ($weight&lt;=0) {
        print_r($pallets);
        exit();
    }
}

pallet_size($total_weight);
</code></pre>

<p>Perhaps I'm just going about this the wrong way entirely?</p>
