Return result_array codeigniter
-
Having the following table:
tbl_service_event
`id` INT(11) NOT NULL AUTO_INCREMENT, `descricao` VARCHAR(255) NULL DEFAULT NULL, `evento_id` INT(11) NOT NULL, `devedor_id` INT(11) NOT NULL, `negociacao_id` INT(11) NOT NULL, `assessoria_id` INT(11) NOT NULL, `complemento` VARCHAR(255) NULL DEFAULT NULL,
And I am generating the following array with the function below:
public function obter_devedor_evento($devedor_id, $id_negociacao_selecionada) { $this->db->from('tbl_atendimento_evento'); $this->db->where('devedor_id',$devedor_id); $this->db->where('negociacao_id',$id_negociacao_selecionada); $query = $this->db->get(); return $query->result_array(); }
Array Managed
Array ( [0] => Array ( [id] => 3 [descricao] => Envio de e-mail [devedor_id] => 1 [evento_id] => 3 [negociacao_id] => 3 [assessoria_id] => 1 [complemento] => Texto do complemento )
[1] => Array ( [id] => 4 [descricao] => Recado [devedor_id] => 1 [evento_id] => 4 [negociacao_id] => 3 [assessoria_id] => 1 [complemento] => Texto do complemento )
)
I want to know how I can include the complement field after
view
Array Pretained
Array
(
[0] => Array
(
[id] => 3
[descricao] => Envio de e-mail
[devedor_id] => 1
[evento_id] => 3
[negociacao_id] => 3
[assessoria_id] => 1
[view][complemento] => Texto do complemento
)[1] => Array ( [id] => 4 [descricao] => Recado [devedor_id] => 1 [evento_id] => 4 [negociacao_id] => 3 [assessoria_id] => 1 [view][complemento] => Texto do complemento )
)
-
Use the function https://secure.php.net/manual/pt_BR/function.array-map.php and make the necessary adjustments, there is no moving, each item should be created and removed when it is unnecessary, for example:
public function obter_devedor_evento($devedor_id, $id_negociacao_selecionada) { $this->db->from('tbl_atendimento_evento'); $this->db->where('devedor_id',$devedor_id); $this->db->where('negociacao_id',$id_negociacao_selecionada); $query = $this->db->get(); return array_map(function($item){ $item['view']['complemento'] = $item['complemento']; // adiciona nova chave unset($item['complemento']); // remove a chave que não precisa return $item; }, $query->result_array()); }