title: Defining elements in an array dynamically
body: <p>I apologize for the title beforehand, but wasn't even sure how to ask the question.</p>
  
  <p>I am working with a json array from a youtube feed.  The feed for a playlist and a user upload are formatted a little differently.  In order to reduce the amount of code I want to define the elements based on the type of feed (playlist/user upload) and insert that into my foreach statement.</p>
  
  <p>The foreach statement for user uploads looks like this:</p>
  
  <pre><code>foreach ($json_output-&gt;data-&gt;items as $data)    {}
  </code></pre>
  
  <p>and for the playlist it needs to look like this:</p>
  
  <pre><code>foreach ($json_output-&gt;data-&gt;items-&gt;video as $data)   {}
  </code></pre>
  
  <p>I have tried defining the statement in a variable beforehand and doing something as follows with no luck:</p>
  
  <pre><code>foreach ($json_output.$feedtype as $data)   {}
  </code></pre>
  
  <p>or</p>
  
  <pre><code>foreach ($json_output + $feedtype as $data)   {}
  </code></pre>