[Solved] Add array values at the start of each subArray from other array


You can use array_walk() with anonymous function and array_unshift():

array_walk
(
    $array1,
    function( &$row, $key, $kind )
    {
        array_unshift( $row, $kind[$key] );
    },
    $array2 
);

eval.in demo

array_walk() modify an array using a custom function. The callable function arguments are the array item (note that we have to set it by reference using &), the array key (optional) and an optional custom parameter (in our case, $array2). Inside the function, with array_unshift()) we can prepend to each item the relative $array2 item, selecting it by key $key.


4

solved Add array values at the start of each subArray from other array