title: PHP Array to Json Object
body: <p>I need to convert a PHP array to JSON but I don't get what I expect.
  I want it to be an object that I can navigate easily with a numeric index.
  Here's an example code:</p>
  <pre><code>$json = array();
  $ip = &quot;192.168.0.1&quot;;
  $port = &quot;2016&quot;;
  array_push($json, [&quot;ip&quot; =&gt; $ip, &quot;port&quot; =&gt; $port]);
  $json = json_encode($json, JSON_PRETTY_PRINT);
  // ----- json_decode($json)[&quot;ip&quot;] should be &quot;192.168.0.1&quot; ----
  echo $json;
  </code></pre>
  <p>This is what I get</p>
  <pre><code>[  
     [  
        &quot;ip&quot; =&gt; &quot;192.168.0.1&quot;,
        &quot;port&quot; =&gt; &quot;2016&quot;
     ]
  ]
  </code></pre>
  <p>But I want to get an object instead of array:</p>
  <pre><code>{  
     &quot;0&quot;: {  
        &quot;ip&quot;: &quot;192.168.0.1&quot;,
        &quot;port&quot;: &quot;2016&quot;
     }
  }
  </code></pre>