I got 2 following arrays:
array(3) {
[0]=>
array(2) {
["id"]=> 5
["moreinfo"]=> 'moreinfo'
}
[1]=>
array(2) {
["id"]=>10,
["moreinfo"]=> 'moreinfo'
}
[2]=>
array(2) {
["id"]=>15
["moreinfo"]=> 'moreinfo'
} ... and so forth
and the second one:
array(3) {
[5] => "Mike"
[10]=> "Bob"
[15]=> "Alice" //here keys are user ids from the first array
I need to merge them in order to add the field name to the first array in order to get the following:
array(3) {
[0]=>
array(3) {
["id"]=> 5,
["name"]=> Mike,
["moreinfo"]=> 'moreinfo'
}
[1]=>
array(3) {
["id"]=>10,
["name"]=> Bob,
["moreinfo"]=> 'moreinfo'
}
[2]=>
array(3) {
["id"]=>15,
["name"]=> Alice,
["moreinfo"]=> 'moreinfo'
}
I tried to use array_merge but it did not produce the desired result. Also I used foreach but it also inserted only 1 name at the end of the array. Any ideas how to fix that? Thank you.
UPD My foreach try:
foreach($arr1 as $k => $v) {
$arr1['name'] = $arr2[$v['id']];
}