title: Sort array based on key => value pair
body: <p>I am trying to sort an array based on the <code>key=&gt;value</code> but I can't get this done. Here is the code I am working out:</p>
  
  <pre><code>$arr = [
      '183034' =&gt; 9,
      '183033' =&gt; 6,
      '183032' =&gt; 3,
      '183002' =&gt; null,
      '182973' =&gt; null,
      '182971' =&gt; null,
      '182969' =&gt; null,
      '182999' =&gt; null,
      '182997' =&gt; null,
      '182995' =&gt; null,
      '182962' =&gt; null,
      '182948' =&gt; null
  ];
  
  $arrTemp = [];
  
  foreach($arr as $key =&gt; $value) {
      $arrTemp[$key] = $value;
  }
  
  array_multisort($arrTemp, SORT_NUMERIC, $arr);
  
  var_export($arrTemp);
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>#php test.php
  array (
    0 =&gt; NULL,
    1 =&gt; NULL,
    2 =&gt; NULL,
    3 =&gt; NULL,
    4 =&gt; NULL,
    5 =&gt; NULL,
    6 =&gt; NULL,
    7 =&gt; NULL,
    8 =&gt; NULL,
    9 =&gt; 3,
    10 =&gt; 6,
    11 =&gt; 9,
  )
  </code></pre>
  
  <p>But I expect something like:</p>
  
  <pre><code>array (
      '183002' =&gt; null,
      '182973' =&gt; null,
      '182971' =&gt; null,
      '183032' =&gt; 3,
      '182969' =&gt; null,
      '182999' =&gt; null,
      '183033' =&gt; 6,
      '182997' =&gt; null,
      '182995' =&gt; null,
      '183034' =&gt; 9,
      '182962' =&gt; null,
      '182948' =&gt; null    
  );
  </code></pre>
  
  <p>Where value define the position where the item should be moved on. In other words let's take an example by words: <code>'183032' =&gt; 3</code> this item is holding position 3 on the result array so what I should do is keep the same array order but move that item to position 3 as you may notice on the output array. Same for <code>'183033' =&gt; 6</code> where this one holds position 6 so I reorder the whole array to move this to position 6 and so on. Can any give me some help?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>What about if I change original <code>$arr</code> into this: </p>
  
  <pre><code>$arr = [
      '183034' =&gt; ['sort_position' =&gt; 9],
      '183033' =&gt; ['sort_position' =&gt; 5],
      '183032' =&gt; ['sort_position' =&gt; 3],
      '183002' =&gt; [],
      '182973' =&gt; [],
      '182971' =&gt; [],
      '182969' =&gt; [],
      '182999' =&gt; [],
      '182997' =&gt; [],
      '182995' =&gt; [],
      '182962' =&gt; [],
      '182948' =&gt; []
  ];
  </code></pre>
  
  <p>Is almost the same but this is how the array should look (just an example) and arrays with <code>[]</code> should have other keys inside I just don't write them here because the relevant is <code>sort_position</code>.</p>