Calculate closest matches from array value combinations
<p>I have an array of part lengths, for examples sake:-</p>

<pre><code>array(150, 180, 270);
</code></pre>

<p>I then have a measurement <code>($a = 440)</code></p>

<p>I need to calculate the two <strong>closest</strong> possible combinations of lengths which are greater than <code>$a</code> without manually having to write hundreds of possible combinations in order to work it out.</p>

<p>So:</p>

<p><code>150</code><br>
<code>180</code><br>
<code>270</code>  </p>

<p><code>150 + 150</code><br>
<code>150 + 180</code><br>
<code>150 + 270</code>  </p>

<p><code>180 + 180</code><br>
<code>180 + 270</code></p>

<p><code>270 + 270</code>  </p>

<p><code>150 + 150 + 150</code><br>
<code>150 + 150 + 180</code></p>

<p>..and so on.</p>

<p>This will need to run for a set number of times, rather than just finding the first two matches and stopping, as <code>150 + 150 + 150</code> would be a <strong>closer</strong> match to <code>$a</code> than <code>270 + 270</code> but may run after.</p>

<p>edit: I also need to store the combination of parts which made up the match, preferably in an array.</p>

<p>I hope I've explained this well enough for somebody to understand.</p>
