Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Think this will make you happy :-)</p> <pre><code> $data = array( array('id' =&gt; 1, 'distance' =&gt; rand(1,100000)), array('id' =&gt; 2, 'distance' =&gt; rand(1,100000)), array('id' =&gt; 3, 'distance' =&gt; rand(1,100000)), array('id' =&gt; 4, 'distance' =&gt; rand(1,100000)), array('id' =&gt; 5, 'distance' =&gt; rand(1,100000)), array('id' =&gt; 6, 'distance' =&gt; rand(1,100000)), array('id' =&gt; 7, 'distance' =&gt; rand(1,100000)), array('id' =&gt; 8, 'distance' =&gt; rand(1,100000)), ); echo "--raw data--\n"; var_dump($data); function distanceSorter($a, $b) { return $a['distance'] - $b['distance']; } usort($data, 'distanceSorter'); echo "--sorted data--\n"; var_dump($data); echo "--grab first result ( lowest )--\n"; var_dump($data[0]); GIVES --raw data-- array(8) { [0]=&gt; array(2) { ["id"]=&gt; int(1) ["distance"]=&gt; int(27573) } [1]=&gt; array(2) { ["id"]=&gt; int(2) ["distance"]=&gt; int(93357) } [2]=&gt; array(2) { ["id"]=&gt; int(3) ["distance"]=&gt; int(84515) } [3]=&gt; array(2) { ["id"]=&gt; int(4) ["distance"]=&gt; int(13666) } [4]=&gt; array(2) { ["id"]=&gt; int(5) ["distance"]=&gt; int(11810) } [5]=&gt; array(2) { ["id"]=&gt; int(6) ["distance"]=&gt; int(37548) } [6]=&gt; array(2) { ["id"]=&gt; int(7) ["distance"]=&gt; int(10705) } [7]=&gt; array(2) { ["id"]=&gt; int(8) ["distance"]=&gt; int(73548) } } --sorted data-- array(8) { [0]=&gt; array(2) { ["id"]=&gt; int(7) ["distance"]=&gt; int(10705) } [1]=&gt; array(2) { ["id"]=&gt; int(5) ["distance"]=&gt; int(11810) } [2]=&gt; array(2) { ["id"]=&gt; int(4) ["distance"]=&gt; int(13666) } [3]=&gt; array(2) { ["id"]=&gt; int(1) ["distance"]=&gt; int(27573) } [4]=&gt; array(2) { ["id"]=&gt; int(6) ["distance"]=&gt; int(37548) } [5]=&gt; array(2) { ["id"]=&gt; int(8) ["distance"]=&gt; int(73548) } [6]=&gt; array(2) { ["id"]=&gt; int(3) ["distance"]=&gt; int(84515) } [7]=&gt; array(2) { ["id"]=&gt; int(2) ["distance"]=&gt; int(93357) } } --grab first result ( lowest )-- array(2) { ["id"]=&gt; int(7) ["distance"]=&gt; int(10705) } </code></pre> <p>Short version</p> <pre><code>function distanceSorter($a, $b) { return $a['distance'] - $b['distance']; } usort($data, 'distanceSorter'); // if you really just want the lowest value $lowestDistance = array_shift(usort($data, 'distanceSorter'); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload