I have a function that parses the 'entry's in a nested array:
$data = Array(
[date] => 'date'
[entry] => Array(
[0] => Array(
[Title] => 'title0'
[Price] => 'price0'
)
[1] => Array(
[Title] => 'title1'
[Price] => 'price1'
)
)
)
Looping through this with a foreach($data['entry'] as $entry){
works great if there is more than one entry. However, it there is only one entry I am served:
$data = Array(
[date] => 'date'
[entry] => Array(
[Title] => 'title'
[Price] => 'price'
)
)
And the foreach loop fails.
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?
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...