MoFish Posted February 12, 2015 Share Posted February 12, 2015 Hi, I have the following code which works well. $this->data['results'] = $this->domain_status_model->get(); foreach($this->data['results'] as $result){ $result->domainstatus_items = $this->domain_model->get_by_status($result->domainstatus_id); I would like the ability to target my array a little more specifically. I therfore am trying to replace the domainstatus_item portion using a returned value from another query. When I try this, it does not appear to be working, probably due to a simple mistake. I have tried using . + and & operators in order for it to work, however am not having much success. $this->data['results'] = $this->domain_status_model->get(); foreach($this->data['results'] as $result){ $result->domainstatus_$result->domainstatus_title = $this->domain_model->get_by_status($result->domainstatus_id); In summary, the value returned from $result->domainstatus_title is for example 'pending' and I am trying to get the following: $result->domainstatus_pending = $this->domain_model->get_by_status($result->domainstatus_id); Any help would be much appriciated. Kind regards, MoFish Quote Link to comment https://forums.phpfreaks.com/topic/294564-objects-and-assigning-a-value-query/ Share on other sites More sharing options...
Solution CroNiX Posted February 12, 2015 Solution Share Posted February 12, 2015 Try something like: $method = 'domainstatus_' . $result; $result->$method->domainstatus_title = $this->domain_model->get_by_status($result->domainstatus_id); Quote Link to comment https://forums.phpfreaks.com/topic/294564-objects-and-assigning-a-value-query/#findComment-1505573 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.