Query result as an indexed array or object by index of choice |
Very often I need to index my array or object by a certain key like this:
PHP Code: $unindexed = $model->select('id, filter_id, value_name') PHP Code: $indexed = array_column($unindexed, null, 'id'); What about a built in function in a model? like this: PHP Code: $indexed = $model->select('id, filter_id, value_name') So far I have a blunt copy of findAll(): PHP Code: public function getResultKey(string $key, int $limit = 0, int $offset = 0) It works as expected, it can return an array of arrays or objects depending on your models returnType. Also it can use integer or string key for indexing. But, with it being just a copy of findAll() it seems like bloatware. If anyone has better ideas of how to implement this, or if you think its worth it, or make it chain with other methods that would be nice. Otherwise, I can usually just do this: PHP Code: $indexed = array_column($model->select('id, filter_id, value_name')
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
|
Messages In This Thread |
Query result as an indexed array or object by index of choice - by Leo - 04-22-2020, 12:04 PM
RE: Query result as an indexed array or object by index of choice - by rmilecki - 11-14-2020, 02:59 PM
RE: Query result as an indexed array or object by index of choice - by paulbalandan - 11-16-2020, 11:16 AM
RE: Query result as an indexed array or object by index of choice - by rmilecki - 11-16-2020, 01:26 PM
RE: Query result as an indexed array or object by index of choice - by paulbalandan - 11-17-2020, 08:46 AM
|