title: Force json_encode to return array instead objects
body: <p>I've been wondering if it's possible to force <code>json_encode</code> into returning <code>Array</code> instead an <code>Object</code> while still keeping the "integer" index.</p>
  
  <p>What am I trying to achieve if you're asking is an array of usernames ( with their userID's as keys in the array ).</p>
  
  <p>So if I have a list of mutual friends like this in PHP:</p>
  
  <pre><code>1 =&gt; 'John Doe',
  2 =&gt; 'Jane Doe',
  5 =&gt; 'Oliver Natefield',
  11 =&gt; 'Chris Cole'
  </code></pre>
  
  <p>I'd like to use <code>json_encode</code> and I tried two methods.</p>
  
  <p>First one is by simply adding into an empty PHP Array, values to their respective index ( userID ).</p>
  
  <pre><code>&lt;?php
      $list = array( );
  
      foreach ( $friends as $userID =&gt; $name )
          $list[ $userID ] = $name;
  
      echo json_encode( $list );
  ?&gt;
  </code></pre>
  
  <p>That creates me an <code>Object</code> sadly. Ok, then I tried something else...</p>
  
  <pre><code>&lt;?php
      $list = array( );
  
      foreach ( $users as $userID =&gt; $name )
          array_splice( $list, $userID, 0, $name );
  
      echo json_encode( $list );
  ?&gt;
  </code></pre>
  
  <p>Again, failed, this time, it's an <code>Array</code>, but the <code>indexes</code> are not taken into consideration. </p>
  
  <p>I know that.. the array should be like :</p>
  
  <pre><code>undefined, // userID 0
  'John Doe', // userID 1
  'Jane Doe', // userID 2
  undefined, // userID 3
  undefined,  // userID 4
  'Oliver Natefield', // userID 5
  undefined, //userID 6
  undefined, // etc
  </code></pre>
  
  <p>But... if I have a friend with <code>userID</code> with the index <code>1504</code> .. shouldn't there be a memory downside ?</p>
  
  <p>And while we're at it, can I see how much memory does an array of <code>1000</code> undefined elements use ? It's relevant because if it consumes too much memory, I'll just have to search through an array of objects for a <code>username</code> after a specific <code>userID</code>.</p>