title: PHP Array Sorting Top 3
body: <p>This is my input data:</p>
  
  <pre><code>Array(
       [0] =&gt; Array(
            [name_id] =&gt; 1
            [name] =&gt; An
            [grade_point] =&gt; 19
       )
       [1] =&gt; Array(
            [name_id] =&gt; 3
            [name] =&gt; Sin
            [grade_point] =&gt; 22
       )
       [2] =&gt; Array(
            [name_id] =&gt; 9
            [name] =&gt; Xi
            [grade_point] =&gt; 18
       )
       [3] =&gt; Array(
            [name_id] =&gt; 6
            [name] =&gt; Ruan
            [grade_point] =&gt; 20
       )
  )
  </code></pre>
  
  <p>This is the code that I've made:</p>
  
  <p>php</p>
  
  <pre><code>$top_academic = $academic;
  foreach ($top_academic as $key =&gt; $row) {
  
      $name_id[$key] = $row['name_id'];
      $name[$key] = $row['name'];
      $grade_point[$key] = $row['grade_point'];
  )
  array_multisort($grade_point, SORT_DESC, $top_akademik);
  </code></pre>
  
  <p>This sorts the data based on grade point, so the output looks like this:</p>
  
  <pre><code>Array(
       [0] =&gt; Array(
            [name_id] =&gt; 3
            [name] =&gt; Sin
            [grade_point] =&gt; 22
       )
       [1] =&gt; Array(
            [name_id] =&gt; 6
            [name] =&gt; Ruan
            [grade_point] =&gt; 20
       )
       [2] =&gt; Array(
            [name_id] =&gt; 1
            [name] =&gt; An
            [grade_point] =&gt; 19
       )
       [3] =&gt; Array(
            [name_id] =&gt; 9
            [name] =&gt; Xi
            [grade_point] =&gt; 18
       )
  )
  </code></pre>
  
  <p>I want it to only output the first three in the sorted array, but I can't figure out how to implement it. Any help would be appreciated!</p>