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

Php - Delimiter must not be alphanumeric or backslash -

trac - Modifying workflow to add a status and split on ticket type -

Delphi interface implements -