title: PHP Foreach loop with a single element
body: <p>I have a function that parses the 'entry's in a nested array:</p>
  
  <pre><code>$data = Array(
     [date] =&gt; 'date'
     [entry] =&gt; Array(
        [0] =&gt; Array(
           [Title] =&gt; 'title0'
           [Price] =&gt; 'price0'
        )
        [1] =&gt; Array(
           [Title] =&gt; 'title1'
           [Price] =&gt; 'price1'
        )
     )
   )
  </code></pre>
  
  <p>Looping through this with a <code>foreach($data['entry'] as $entry){</code> works great if there is more than one entry. However, it there is only one entry I am served:</p>
  
  <pre><code> $data = Array(
     [date] =&gt; 'date'
     [entry] =&gt; Array(
        [Title] =&gt; 'title'
        [Price] =&gt; 'price'
     )
   )
  </code></pre>
  
  <p>And the foreach loop fails.</p>
  
  <p>Is there an elegant way to write a foreach that will grab each entry[0], entry[1] sub array (like normal) or back off one level if there is only one entry and grab the entire 'entry' array instead?</p>
  
  <hr>
  
  <p>Addendum: the stuff I'm doing on the entries is pretty involved... I supposed I could separate that out into a different function, do an if(is_array) check then call the function once, or for each... but that seems inelegant...</p>