How to access object data inside an array and object after json_encode executed?
<p>I have a json data from API and i want to insert them to my database table. I have extract <code>$data</code> using <code>json_encode</code> function, but when i tried to access data inside <code>$myJson</code> with some of this code, it gives me an error result.</p>
<pre><code>$data = '{&quot;posts&quot;:[{&quot;post&quot;:{&quot;math_score&quot;:&quot;85&quot;,&quot;history_score&quot;:&quot;70&quot;}}]}';
$myJson = json_decode($data);

foreach ($myJson as $mj){
    echo $mj['math_score'];
    // echo $mj-&gt;math_score; &lt;= error
    // echo $mj[0]-&gt;post-&gt;math_score; &lt;= error
    // echo $mj-&gt;post-&gt;math_score; &lt;= error
}
</code></pre>
<blockquote>
<p>The error : <code>Invalid argument supplied for foreach()</code>.</p>
</blockquote>
<p>sorry for my bad grammar, any answer will be greatly appreciated. Thanks</p>