title: JSON decode get the last element, PHP end
body: <p>I want to get the last element in the JSON decoded array,
  Error I am getting </p>
  
  <blockquote>
    <p>Warning: end() expects parameter 1 to be array</p>
  </blockquote>
  
  <p><code>$data</code> output</p>
  
  <pre><code>stdClass Object ( 
      [contact001] =&gt; stdClass Object ( [age] =&gt; 33 [name] =&gt; Robert [tel] =&gt; 87778787878787878 ) 
      [contact002] =&gt; stdClass Object ( [age] =&gt; 33 [name] =&gt; Calvin [tel] =&gt; 87778787878787878 ) 
  )
  </code></pre>
  
  <p>PHP code:</p>
  
  <pre><code>$namejson = $firebase-&gt;get(DEFAULT_PATH . '/name/');
  
  $data=json_decode($namejson);
  
  foreach ($data as $key =&gt; $value) {
      echo end($key);
  }
  </code></pre>
  
  <blockquote>
    <p>Warning: end() expects parameter 1 to be array</p>
  </blockquote>