title: Get ObjectId MongoDB via PHP
body: <p>Here's my script</p>
  
  <pre><code>$terms = ['username' =&gt; $uri];
  $user = $collection-&gt;findOne($terms);
  </code></pre>
  
  <p>result </p>
  
  <pre><code>array (size=4)
    '_id' =&gt; 
      object(MongoId)[29]
        public '$id' =&gt; string '4ff6e96bb0b4599016000006' (length=24)
    'username' =&gt; string 'me' (length=10)
    'name' =&gt; string 'Yes, It's me!' (length=16)
  </code></pre>
  
  <p><strong>Get Name</strong></p>
  
  <p><code>$name = $user['name'];</code></p>
  
  <p>But, how can i get <code>$user['_id']</code> ?</p>
  
  <p>I try <code>$user['_id']</code> NOT WORK</p>
  
  <p>Please help. Thanks</p>
  
  <p><strong>UPDATE</strong> </p>
  
  <p>Problem solved with <code>$user['_id']-&gt;{'$id'}</code></p>