In PHP
I have an array that I will show below, I sent a request to the model and it sent me retorna el id
, the idea is that I can 'set' 'id_company' => $insert_id
in the array $datos
, but when I made array_push($datos, ['id_company' => $insert_id])
an array I created an array in that same array and that is not the idea.
#Este es el arreglo original
$datos = [
'id_rol_user' => 4,
'name' => $this->input->post('name'),
'lastname' => $this->input->post('lastname'),
'email' => $this->input->post('email'),
'username' => $this->input->post('username'),
'password' => sha1($this->input->post('password')),
'photo' => $ruta,
'status' => 1,
];
#Como deberia de quedar
$datos = [
'id_rol_user' => 4,
'name' => $this->input->post('name'),
'lastname' => $this->input->post('lastname'),
'email' => $this->input->post('email'),
'username' => $this->input->post('username'),
'password' => sha1($this->input->post('password')),
'photo' => $ruta,
'status' => 1,
'id_company' => $insert_id,
];
To add the element you create it as direct.
In PHP to change the value for a certain index of an array it is enough to assign the new value .
For example, in the following code I change the number of apples:
The result of the execution will be:
What you were doing, with array_push() according to the PHP documentation was "inserting one or more elements at the end of an array" .