PHP: Fetch top-5 values for multi dimension array
<p>I have an array:</p>

<pre><code>Array ( [0] =&gt; Array ( [trade] =&gt; Sealwell
[open] =&gt; 7
[closed] =&gt; 0
) [1] =&gt; Array ( [trade] =&gt; Add-a-Line
[open] =&gt; 2
[closed] =&gt; 0
) [2] =&gt; Array ( [trade] =&gt; C.T.A
[open] =&gt; 5
[closed] =&gt; 0
) [3] =&gt; Array ( [trade] =&gt; Chadoak
[open] =&gt; 1
[closed] =&gt; 0
) [4] =&gt; Array ( [trade] =&gt; Chevron
[open] =&gt; 0
[closed] =&gt; 1
) [5] =&gt; Array ( [trade] =&gt; City Pro Sign
[open] =&gt; 8
[closed] =&gt; 10
) [6] =&gt; Array ( [trade] =&gt; ControlFab
[open] =&gt; 4
[closed] =&gt; 0
) [7] =&gt; Array ( [trade] =&gt; Detail
[open] =&gt; 1
[closed] =&gt; 0
) [8] =&gt; Array ( [trade] =&gt; Fabcot to advise
[open] =&gt; 1
[closed] =&gt; 0
) [9] =&gt; Array ( [trade] =&gt; FireBase
[open] =&gt; 2
[closed] =&gt; 0
) [10] =&gt; Array ( [trade] =&gt; Gemwood
[open] =&gt; 1
[closed] =&gt; 0
) [11] =&gt; Array ( [trade] =&gt; HG
[open] =&gt; 3
[closed] =&gt; 0
) [12] =&gt; Array ( [trade] =&gt; I.E.S
[open] =&gt; 11
[closed] =&gt; 30
) [13] =&gt; Array ( [trade] =&gt; Integral
[open] =&gt; 5
[closed] =&gt; 0
) [14] =&gt; Array ( [trade] =&gt; McGee
[open] =&gt; 26
[closed] =&gt; 0
) [15] =&gt; Array ( [trade] =&gt; McGee / Detail
[open] =&gt; 1
[closed] =&gt; 0
) [16] =&gt; Array ( [trade] =&gt; McGee / Sealwell
[open] =&gt; 1
[closed] =&gt; 0
) [17] =&gt; Array ( [trade] =&gt; McGee / Spence
[open] =&gt; 0
[closed] =&gt; 1
) [18] =&gt; Array ( [trade] =&gt; Meridian
[open] =&gt; 7
[closed] =&gt; 0
) [19] =&gt; Array ( [trade] =&gt; Mulgrave
[open] =&gt; 2
[closed] =&gt; 0
) [20] =&gt; Array ( [trade] =&gt; Mulgrave / McGee
[open] =&gt; 1
[closed] =&gt; 0
) [21] =&gt; Array ( [trade] =&gt; Precast
[open] =&gt; 1
[closed] =&gt; 0
) [22] =&gt; Array ( [trade] =&gt; R&amp;D
[open] =&gt; 1
[closed] =&gt; 0
) [23] =&gt; Array ( [trade] =&gt; Spence
[open] =&gt; 1
[closed] =&gt; 0
) [24] =&gt; Array ( [trade] =&gt; Star
[open] =&gt; 2
[closed] =&gt; 0
) [25] =&gt; Array ( [trade] =&gt; Tieman
[open] =&gt; 2
[closed] =&gt; 0
) [26] =&gt; Array ( [trade] =&gt; TTI
[open] =&gt; 3
[closed] =&gt; 0
) ) 
</code></pre>

<p>and I want to fetch Top-5 trade with highest Open value and Top-5 with highest of count Open+Closed, like</p>

<p><strong>Top-5 Trade with highest Open values</strong></p>

<pre><code>Array ( [0] =&gt; Array ( [trade] =&gt; McGee) [open] =&gt; 26 ) 
( [1] =&gt; Array ( [trade] =&gt; I.E.S) [open] =&gt; 11 ) 
( [2] =&gt; Array ( [trade] =&gt; City Pro Sign) [open] =&gt; 8 ) 
( [3] =&gt; Array ( [trade] =&gt; Meridian) [open] =&gt; 7 ) 
( [4] =&gt; Array ( [trade] =&gt; Sealwell) [open] =&gt; 7 ) 
)
</code></pre>

<p><strong>Top-5 Trades with highest count of Open+Closed</strong></p>

<pre><code>Array ( [0] =&gt; Array ( [trade] =&gt; I.E.S) [open] =&gt; 11 [closed] =&gt; 30 [count] =&gt; 41) 
    ( [1] =&gt; Array ( [trade] =&gt; McGee) [open] =&gt; 26 [closed] =&gt; 0 [count] =&gt; 26) 
    ( [2] =&gt; Array ( [trade] =&gt; City Pro Sign) [open] =&gt; 8 [closed] =&gt; 10 [count] =&gt; 18) 
    ( [3] =&gt; Array ( [trade] =&gt; Meridian) [open] =&gt; 7 [closed] =&gt; 0 [count] =&gt; 7) 
    ( [4] =&gt; Array ( [trade] =&gt; Sealwell) [open] =&gt; 7 [closed] =&gt; 0 [count] =&gt; 7) 
    )
</code></pre>
