Since I started to write more code in OOP I always run into a in my point of view "code styling" problem. I want to add some additional data to an existing object. When I used arrays this was easily possible with foreach because every array item got its own key. Now with objects I didn't found a way how I can access each item with an key.
$data_items = $this->model->get_function();
$data_items = (array) $data_items;
foreach ($data_items as $key => $row)
{
$data_items[$key]['additional_data'] = 'additional_data';
}
$data_items = (object) $data_items;
I think my code is only a work around. Can please somebody tell me if I can get rid off the code line "$data_items = (array) $data_items;" and "$data_items = (object) $data_items;".
Thanks to everybody who replied to my question!
Until now I didn't realized that it is so easy what I tried to achieve:
foreach ($data_items as $row)
{
$row->additional_data = 'additional_data';
}