I have an object, within an array, that is itself within an array - like this:
Array (
[0] => Array
(
[year] => 2010
[0] => stdClass Object
(
[ticker] => AAA
[exchange] => LSE
[cur_value] => 100
)
[1] => stdClass Object
(
[ticker] => BBB
[exchange] => LSE
[cur_value] => 200
)
)
[1] => Array
(
[year] => 2015
[0] => stdClass Object
(
[ticker] => AAA
[exchange] => LSE
[cur_value] => 100
)
[1] => stdClass Object
(
[ticker] => BBB
[exchange] => LSE
[cur_value] => 200
)
)
)
I want to be able to loop through the first level array, and then create a table with the data it contains. The table will use the 'year' as its name, and the the stdClass Objects will be the data that goes into the table.
The problem I am having is that that the ['year'] interferes with the first row of the table and I cannot seem to skip it - e.g. by putting a counter in and skipping the first foreach iteration or by using is_object.
The error I am getting (and I understand why I get it) is 'You are trying to get property of non-object'.
I have looked at other SO questions but they I haven't been able to find this exact problem e.g this one - Notice: Trying to get property of non-object error
Can anyone help me skip that 'year'? The PHP code I have is like this:
foreach($portfolios as $portfolio){
echo $portfolio['year'];
echo '<table>';
echo '<tr>';
echo '<th>Ticker</th>';
echo '<th>Exchange</th>';
echo '<th>Value</th>';
echo '</tr>';
foreach($portfolio as $folio){
echo '<tr>';
echo '<td>'.$folio->ticker.'</td>';
echo '<td>'.$folio->exchange.'</td>';
echo '<td>'.$folio->cur_value.'</td>';
echo '</tr>';
}
echo '</table>';
}