PHP, sort array by key length & value
<p>The finished array would look something like this:</p>

<pre><code>array(

'foo bar bar foo' =&gt; 10,
'foo' =&gt; 10,
'foo bar bar bar foo' =&gt; 6,
'foo bar' =&gt; 6,
'bar' =&gt; 6,
'b' =&gt; 5

)
</code></pre>

<p>So the values are sorted first by the value, and then by the length of the key.</p>

<p>In MySQL I'd do this: </p>

<pre><code>SELECT product, qty FROM stock ORDER BY qty DESC, LENGTH(product) DESC 
</code></pre>

<p>But I'd like to do it in PHP.</p>
