PHP get keys in nested array using array_keys( ) <p>I have a $results array produced from a query and I would like to output a table in html. I would like the header to be "id", "length" and "sample_id". Since the header changes every time, so I used</p> <pre><code>$keys = array_keys($results[0]); </code></pre> <p>I got "array_keys() expects parameter 1 to be array" error. If the nested part is not an array, how should I get the keys?</p> <pre><code>array:59 [▼ 0 =&gt; {#160 ▼ +"id": 204 +"length": 233 +"sample_id": "ad3" } 1 =&gt; {#161 ▼ +"id": 205 +"length": 733.5 +"sample_id": "bt7r" } 2 =&gt; {#162 ▶} 3 =&gt; {#163 ▶} 4 =&gt; {#164 ▶} 5 =&gt; {#165 ▶} </code></pre>