I am having a hard time getting the correct data out of an array. I wrote a nested foreach loop but the inner loop is throwing the "Invalid argument supplied for foreach()" error. Can someone please help me out with this? Thanks.
foreach($row as $val)
{
echo $val['title'].'<br>';
echo $val['author'].'<br>';
echo $val['post'].'<br>';
echo $val['entry_date'].'<br>';
echo $val['comments'].'<br>';
foreach($val as $val2)
{
echo $val['comments'].'<br>';
}
}
Array
(
[title] => First Blog
[author] => Administrator
[post] => Testing entry number one
[entry_date] => Fri, 23 Oct 2009
[comments] => Array
(
[0] => Array
(
[commenter] => Sally Anderson
[comments] => comment 1 post 1
[comment_date] => October 24th, 2009 at 5:24 AM
)
[1] => Array
(
[commenter] => Mike Jones
[comments] => comment 2 post 1
[comment_date] => October 24th, 2009 at 5:21 AM
)
)
)
Array
(
[title] => Second Blog
[author] => Administrator
[post] => Testing entry number two
[entry_date] => Sat, 24 Oct 2009
[comments] => Array
(
[0] => Array
(
[commenter] => Sally Anderson
[comments] => comment 1 post 2
[comment_date] => October 24th, 2009 at 5:21 AM
)
[1] => Array
(
[commenter] => Mike Jones
[comments] => comment 2 post 2
[comment_date] => October 24th, 2009 at 5:21 AM
)
)
)