i've 2 multidimensional arrays , need merge both specific key. tried array_merge_recursive , array_search poor results.
so,
main arrays:
array ( [group] => array ( [subgroup] => array ( [items] => array ( [item 1] => web development [item 2] => dba [item 3] => qa ) ) ) ) /* ------------ */ array ( [item 1] => array ( [user 1] => array ( [properties] => array ( [id] => conexion_1624 [name] => jhon doe ) ) [user 2] => array ( [properties] => array ( [id] => conexion_2001 [name] => alice , bob ) ) ) )
expected result:
array ( [group] => array ( [subgroup] => array ( [items] => array ( [item 1] => array ( [user 1] => array ( [properties] => array ( [id] => conexion_1624 [name] => jhon doe ) ) [user 2] => array ( [properties] => array ( [id] => conexion_2001 [name] => alice , bob ) ) ) [item 2] => dba [item 3] => qa ) ) ) )
if arrays structures not changed
foreach($the2nd $key => $item) $the1st['group']['subgroup']['items'][$key] = $item; update due discussion in comments
if in 1st array items may not on same level, such code find them
array_walk_recursive ( $the1nd , function($v, $k, $the2nd) { if(isset($the2nd[$k])) $v = $the2nd[$k]; }, $the2nd);
Comments
Post a Comment