1
Having the following table:
tbl_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();
}
Generated Array
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 the view
Desired Array
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
)
)
Um, perfect, it really worked. If you add other items to the view, how can it be done ?
– Wagner Fillio
I must repeat
item
andunset
inside the array_map?– Wagner Fillio
@Wagnerson the logic to add is
$item['view']['nova _ chave'] = valor
– novic
@Wagnerfilho the logic to remove is
unset($item['nome _ da _ chave']);
– novic
Okay, I tried and I got it. Thank you!!
– Wagner Fillio
Excuse the question, but it is possible to use
unset
inrow_array
?– Wagner Fillio
@Wagnerson in the result of it yes! is the same thing.
– novic
It’s because I’m getting this feedback:
Cannot unset string offsets
, doing as follows:return array_map(function($item){
 unset($item['dt_cadastro']);
 unset($item['dt_atualizacao']);
 unset($item['id']);
 return $item;
 },
 
 $query->row_array());
– Wagner Fillio
The
$query->row_array()
returns a simple array does not need to interact, because it is not a collection. place$item = $query->row_array();
then putunset($item['id']);
that is, it does not need toarray_map
, maybe you don’t even have to do it already in SQL if you can remove what you don’t need...– novic
Perfect, it worked. Thank you
– Wagner Fillio