title: php custom array sort only for 4 first elements
body: <p>I need to sort an array that first four elements will be defined manually and the rest alphabetically. How can I achieve this?</p>
  
  <pre><code>    $array = array('navigation' =&gt; array('label' =&gt; 'nav'), 
                     'sponsors' =&gt; array('label' =&gt; 'spo'),
                     'points' =&gt; array('label' =&gt; 'poi'),
                     'direction' =&gt; array('label' =&gt; 'dir'),
                     'time' =&gt; array('label' =&gt; 'tim'),
                     'statistics' =&gt; array('label' =&gt; 'sta'),
                     'height' =&gt; array('label' =&gt; 'hei'),
                     'opacity' =&gt; array('label' =&gt; 'opa'),
                     'saturation' =&gt; array('label' =&gt; 'sat'),
                     'size' =&gt; array('label' =&gt; 'size'),
                     'attribute' =&gt; array('label' =&gt; 'att')
                     );
  </code></pre>
  
  <p>First four elements should be <strong>size, opacity, time, points</strong> and the rest should be alphabetically.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Comments requested to show my attempts. I tried sorting it with uasort function but it's not working at all. Also I have no idea why.</p>
  
  <pre><code>    $order = array('size', 'opacity', 'time', 'points');
  
      uasort($array, function ($a, $b) use ($order) {
          $pos_a = array_search($a, $order);
          $pos_b = array_search($b, $order);
          return $pos_a - $pos_b;
      });
  </code></pre>