My question is:
I have 2 arrays :
teste [
id: 20,
campo: nada
etc,
id: 30,
campo: nada
etc,
]
teste 2 [
id: 12,
nome: maria,
etc,
id: 30,
nome: joão,
etc,
]
All ids
will hit, that is, the ids
of the 1st array are all present in the 2nd array , however out of order and not you can sort because this comes from a randomly generated JSON.
I need to check when ids
are the same, and if so, create a new key in the 1st array with the field data nome
of the 2nd array .
I did
foreach ($array1 as $teste) {
if($teste['id']==$array2['id']) {
$array1['nome'] = $array2['nome'];
}
}
It does not work, since the ids
that does not hit $array1['nome']
is left blank.
Is there a simple solution?