title: Decode sparse json object to php array
body: <p>I can create a sparse php array (or map) using the command:</p>
  
  <pre><code>$myarray = array(10=&gt;'hi','test20'=&gt;'howdy');
  </code></pre>
  
  <p>I want to serialize/deserialize this as JSON. I can serialize it using the command:</p>
  
  <pre><code>$json = json_encode($myarray);
  </code></pre>
  
  <p>which results in the string <code>{"10":"hi","test20":"howdy"}</code>. However, when I deserialize this and cast it to an array using the command:</p>
  
  <pre><code>$mynewarray = (array)json_decode($json);
  </code></pre>
  
  <p>I seem to lose any mappings with keys which were not valid php identifiers. That is, <code>mynewarray</code> has mapping <code>'test20'=&gt;'howdy'</code>, but not <code>10=&gt;'hi'</code> nor <code>'10'=&gt;'hi'</code>.</p>
  
  <p>Is there a way to preserve the numerical keys in a php map when converting to and back from json using the standard <code>json_encode</code> / <code>json_decode</code> functions?</p>
  
  <p>(I am using PHP Version 5.2.10-2ubuntu6.4.)</p>