私はこのような配列を構築しています:
$result = $this->db->get($this->_table);
foreach ($result->result_array() as $row)
{
$list->$row['categories_id'] = array('total_amount' => $row['total_amount'], 'other_stuff' => 'stuff');
}
これにより、「空のプロパティにアクセスできません」という致命的な例外が発生します
<?foreach ($category_list as $index => $row) {?>
<td><?=$row?></td>
<td><?=$list->$index['total_amount']?></td>
<?}?>
しかし、これは機能します
<?foreach ($category_list as $index => $row) {?>
<td><?=$row?></td>
<? $temp = $list->$index; ?>
<td><?=$temp['total_amount']?></td>
<?}?>
このオブジェクトから「合計金額」を取得するより良い方法はありますか?
さらに良い-オブジェクトがこのように機能するようにするにはどうすればよいですか
echo $list->$index->total_amount