2
I have a multidimensional array with the following structure below:
Array
(
[0] => Array
(
[id] => 1877
[type_id] => 4
[service_id] => 1100
)
[1] => Array
(
[id] => 2299
[type_id] => 2
[service_id] => 1148
)
)
I need to dynamically insert a new key associated with a value at the end of each array key to get the following structure below:
Array
(
[0] => Array
(
[id] => 1877
[type_id] => 4
[service_id] => 1100
[nova_chave] => "Novo Valor" <---
)
[1] => Array
(
[id] => 2299
[type_id] => 2
[service_id] => 1148
[nova_chave] => "Novo Valor" <---
)
)
Could someone help me how to implement this solution in PHP?
In order to be able to exemplify in a more complete way, can you explain to me where the data to add comes from? Will each position have a different value? These values will come from an array as it will be?
– Vinicius Gabriel
Vinicius Gabriel, even the data that will be inserted in the new key will come from another array.
– Jorgito da Silva Paiva
This other array from which the data comes has what structure? Is there anything that can identify which value should go to which id for example? Or the order of the positions in their associative array respect the same order of the values that comes from the array?
– Vinicius Gabriel
The other array will also have an id, e.g.: [1] => (['id' => 2299, nova_key => 'New Value']), so you need to compare the ID’s and when they are equal take 'nova_key' => 'New Value' and add in the structure of the 1st array, you can understand?
– Jorgito da Silva Paiva