2
I’m retrieving an object and turning this object into array.
Now, I need to access some elements of this array to fill in these data in the controller (Codeigniter), before returning it as JSON.
To the object below:
{
"contratos":[
],
"id":0,
"id_operador":0,
"pessoa_fisica":{
"id":0,
"rg":"",
"dt_nascimento":"",
"profissao":"",
"salario":"",
"genero":"1"
},
"pessoa_juridica":{
"id":0,
"nome_fantasia":"",
"inscricao_estadual":""
},
"nome":"Wagner Carlos de Jesus Júnior",
"cpf_cnpj":"096.686.256-25",
"emails":[
],
"enderecos":[
],
"telefones":[
],
"crud":null
}
I’m using the function json_decode
and getting the following return with the print_r
$objeto = $_POST['objeto'];
$objeto_decode = json_decode($objeto, true);
print_r($objeto_decode);
And the return is as below, however, I do not know how to access the element individually and fill it manually. For example, fill the element [id_operador]
with the ID (Session) of the logged-in user`
Array
(
[contratos] => Array
(
)
[id] => 0
[id_operador] => 0
[pessoa_fisica] => Array
(
[id] => 0
[rg] =>
[dt_nascimento] =>
[profissao] =>
[salario] =>
[genero] => 1
)
[pessoa_juridica] => Array
(
[id] => 0
[nome_fantasia] =>
[inscricao_estadual] =>
)
[nome] => Wagner Carlos de Jesus Júnior
[cpf_cnpj] => 096.686.256-25
[emails] => Array
(
)
[enderecos] => Array
(
)
[telefones] => Array
(
)
[crud] =>
)
Just make the call $object_decode["id_operator"].
– Diego Schmidt