PHP array replace after matching value [duplicate]

To replace on month it would have to be unique, so just index on that and replace:

$orgigal = array_replace(array_column($orgigal, null, 'month'),
                         array_column($replace, null, 'month'));

Or:

$orgigal = array_column($replace,  null, 'month') + array_column($orgigal, null, 'month');

If you don’t want the month as keys after, then just use array_values.

Leave a Comment