Retrieving Basic Arrays of Data |
I often have the need for a basic array of the row key/ID and a single column's data (think ID and name). With what I know of CI4, I can do the search and end up with an array of arrays with the top level being the array key which is numerical. I then convert this array pretty simply, but am wondering if there is a better, quicker way to get what I really need. Maybe I am missing something but I just don't see what I need in the docs (or I am not searching for the right phrase/command).
For example I need the record ID and the person's name. So I do this: PHP Code: $peopleTemp = $this->mailingModel ->select('id, name_main') Code: id name_main But what I want is actually: Code: id name_main So I end up converting the first one with this: PHP Code: foreach($peopleTemp as $onePerson) { So that in my view I can just do: PHP Code: <?= $people[$record['consigner_id']] ?> Surely there has to be a way to get what I need/want in one step in my controller?
> Surely there has to be a way to get what I need/want in one step in my controller?
I don't know. $people = array_column($peopleTemp, 'name_main', 'id');
|
Welcome Guest, Not a member yet? Register Sign In |