title: assort merge two assorted arrays
body: <p>I am trying to merge two assorted arrays assorting the result as well in PHP this is the code that I have managed to come up with:</p>
  
  <pre><code>&lt;?php
  function assotAssortedArrays($a, $b){
    if (empty($a)){
      return $b;
    }
    if (empty($b)){
      return $a;
    }
    if ($a[0] &lt; $b[0]){
      return array_merge($a[0],  
              array_merge(array_slice($a, 1, count($a)-1), $b));
    } else {
      return array_merge($b[0], 
              array_merge(array_slice($b, 1, count($b)-1), $a));        
    }
  }
  
  $a = array(1,2,3,4,5);
  $b = array(3,4,5,6,7);
  var_dump(assotAssortedArrays($a, $b));
  </code></pre>
  
  <p>The code does not work, this is the error that I am getting:</p>
  
  <pre><code>Warning: array_merge(): Argument #1 is not an array in D:\Web\a\sortArrays.php on line 14
  </code></pre>
  
  <p>Basically the interpreter is saying that argument 1 here <code>array_merge(array_slice($b, 1, count($b)-1), $a));</code> is not and array, but I have done print_r on all elements and it says they are arrays. What am I doing wrong?</p>
  
  <p><strong>Edit</strong>, Thanks to Sam This is the correct code:</p>
  
  <pre><code>function mergeArrays($a, $b){
      if (empty($a)){
          return $b;
      }
      if (empty($b)){
          return $a;
      }
      if ($a[0] &lt; $b[0]){
          $aux[] = $a[0];
          return array_merge($aux, mergeArrays(array_slice($a, 1, count($a)), $b));
      } else {
          $aux[] = $b[0];
          return array_merge($aux, mergeArrays(array_slice($b, 1, count($b)), $a));        
      }
  }
  </code></pre>