I have 2 arrays, each with a date string and a string value representing 'amount'. The first array has a row for every day between start_date and end_date, but has nothing for 'amount'. The second array has fewer rows, but has the amount. I need to merge the 2 arrays so that I end up with a row for every day, with an amount for that day, if there is one.
Array 1: every day, no amount:
Array(
[20040601] => Array( [amount] => )
[20040602] => Array( [amount] => )
...
[20100506] => Array( [amount] => )
[20100507] => Array( [amount] => )
)
Array 2: unique date for each row, has amount, not an entry for every day:
Array(
[20040618] => Array( [amount] => 19764 )
[20040727] => Array( [amount] => 18008 )
...
[20040925] => Array( [amount] => 5480 )
[20041007] => Array( [amount] => 12522 )
)
Result:
Array(
[20040618] => Array( [amount] => 19764 )
[20040619] => Array( [amount] => )
[20040620] => Array( [amount] => 5967)
[20040621] => Array( [amount] => )
...
[20040625] => Array( [amount] => 5480 )
[20040626] => Array( [amount] => 12522 )
[20040627] => Array( [amount] => 4523 )
)
EDIT: Showing the result array a little better.
Resulting array would include a row for every day, with the corresponding amount for that day, if there is one. So basically, merge on the date key and return the date and amount. I've tried to get merge_array to work but I am losing my date in the process. There has to be a native function to do this without resorting to iterative looping through the array.