PHP, Merge keys in multidimensional array -


if have array looks this:

array (     [0] => array     (         [data] => array     (         value1 = 1         value2 = 2     )     )     [1] => array     (            [data] => array     (         value3 = 3         value4 = 4     )     ) ) 

and turn this:

array (     [0] => array     (         [data] => array     (         value1 = 1         value2 = 2         value3 = 3         value4 = 4     )     ) ) 

i want merge identical keys @ same level. best route accomplish this? array_merge functions of use?

i hope makes sort of sense , in advance can get.

you can use array_merge_recursive merge items in original array together. , since function takes variable number of arguments, making unwieldy when number unknown @ compile time, can use call_user_func_array convenience:

$result = call_user_func_array('array_merge_recursive', $array); 

the result have "top level" of input pruned off (logical, since merging multiple items one) keep of remaining structure.

see in action.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -