I'd like to build on $arr1 with the special row from $arr2.
$arr1 = Array
(
[0] => Array
(
[1111] => Array
(
[itemid] => 4321
[itemcode] => item1
[avail] => 0
)
[2222] => Array
(
[itemid] => 4321
[itemcode] => item2
[avail] => 20
)
)
[1] => Array
(
[3333] => Array
(
[itemid] => 1342
[itemcode] => item3
[avail] => 10
)
)
)
$arr2 = Array
(
[1111] => Array
(
[itemid] => 4321
[itemcode] => item1
[special] => 10
)
[2222] => Array
(
[itemid] => 4321
[itemcode] => item2
[special] => 2
)
[3333] => Array
(
[itemid] => 1342
[itemcode] => item3
[special] => 1
)
)
My desired result is like so:
$arr1 = Array
(
[0] => Array
(
[1111] => Array
(
[itemid] => 4321
[itemcode] => item1
[avail] => 0
[special] => 10
)
[2222] => Array
(
[itemid] => 4321
[itemcode] => item2
[avail] => 20
[special] => 2
)
)
[1] => Array
(
[3333] => Array
(
[itemid] => 1342
[itemcode] => item3
[avail] => 10
[special] => 1
)
)
)
I understand how to do this with two mutlidimensional arrays but the additional array wrapping around $arr1 has me thinking I need to for loop but I don't want to make a 3rd new array, just take on the special value to $arr1.
I've tried variations of the following:
$arr1 = array_map(function($v) use($arr2){
$v = (array)$v;
$key = array_search(array_column($v["itemcode"]), array_column($arr2, 'itemcode'));
$v["special"] = $arr2[$key]["special"];
return $v;
}, $arr1);
Which fails to append the data to the special index even though the new index appears in $arr1(new).
Guidance is much appreciated! Maps are so cool and powerful but I cannot seem to grasp their awesomeness in its entirety.
$mini_data?$arr2. I've corrected it