title: Cannot use object of type stdClass as array when looping over regular array
body: <p>I'm trying to access some kind of dynamic key inside of my PHP <code>foreach</code> loop, I'm looping over an array of objects where each <code>$item</code> is a single object containing several key/value pairs, one of the keys is called <code>event_count</code> whilst another is called <code>created_at</code>.</p>
  <p>However, I don't want to hardcode these keys as the user has control over what they want to see, thus I'm pulling through the key that they wish to look at, and it's here where I'm getting this error.</p>
  <pre class="lang-php prettyprint-override"><code>public function getStructure($type, $data, $labelsKey, $dataKey)
    {
        switch ($type) {
          case 'chart':
              $chart = [
                'labels' =&gt; [],
                'data' =&gt; []
              ];
  
              foreach ($data as $key =&gt; $item) {
  
                // TODO: can't use $labelsKey or $dataKey for $item for some reason??
                array_push($chart['labels'], $item[$labelsKey]);
                array_push($chart['data'], $item[$dataKey]);
  
              }
  
              return [
                'chart' =&gt; $chart
              ];
              break;
        }
    }
  </code></pre>
  <p><code>$labelsKey</code> in this context contains a string called 'created_at<code>, whilst </code>$dataKey` contains 'event_count'.</p>
  <p>What am I doing wrong?</p>
  <p>If I change <code>$item[$labelsKey]</code> to <code>$item-&gt;created_at</code> then it works as expected, but this doesn't meet my requirement, would it be a simple case of setting <code>$item-&gt;$labelsKey</code>?</p>