php - Merge two multidimensional arrays, preserve numeric keys, and combine values inside array -
i have 2 arrays , combine / merge / put them together.
$arr1 = array( 0 => array(1, 2), 1 => array(5, 6) ); $arr2 = array( 0 => array(2, 3), 1 => array(6, 7) ); come_together_right_now($arr1, $arr2); // missing function?
and result be:
array ( [0] => array ( [0] => 1 [1] => 2 [2] => 3 ) [1] => array ( [0] => 5 [1] => 6 [2] => 7 )
there way many array functions! array_merge
, array_combine
, recursive alternatives seem replace values , don't preserve numeric keys. how do this?
assuming have same keys!
$result = array(); foreach($arr1 $key=>$array) { $result[$key] = array_merge($array, $arr2[$key]); }
Comments
Post a Comment