I am trying to merge two arrays based on a matching order_id:
Array1:
[0] => Array (
[order_id] => 44446
[carrier_tracking_code] => LB399189926US
)
[1] => Array (
[order_id] => 42816
[carrier_tracking_code] => 9205590221582717353066
)
[2] => Array (
[order_id] => 44490
[carrier_tracking_code] => 9205590221582717353080
)
[3] => Array (
[order_id] => 44507
[carrier_tracking_code] => 9205590221582717353073
)
[4] => Array (
[order_id] => 44437
[carrier_tracking_code] => 9205590221582717353042
)
[5] => Array (
[order_id] => 44519
[carrier_tracking_code] => 9205590221582717352939
)
[6] => Array (
[order_id] => 44561
[carrier_tracking_code] => 9205590221582717353028
)
[7] => Array (
[order_id] => 42985
[carrier_tracking_code] => 9205590221582717353035
)
[8] => Array (
[order_id] => 42673
[carrier_tracking_code] => 9205590221582717353097
)
[9] => Array (
[order_id] => 40197
[carrier_tracking_code] => 9205590221582717353059
)
[10] => Array (
[order_id] => 44733
[carrier_tracking_code] => 92055902215827
)
array2:
[79] => Array (
[order_id] => 44925
[customers_email_address] => test@test.com
[customers_name] => JTest name
)
[80] => Array (
[order_id] => 44923
[customers_email_address] => test@test.com
[customers_name] => Test name
)
[81] => Array (
[order_id] => 44917
[customers_email_address] => test@test.com
[customers_name] => Test name
)
[82] => Array (
[order_id] => 44915
[customers_email_address] => a test@test.com
[customers_name] => Test name
)
My goal is to create a third array that matches the order_id column from both and merges based on that.
I have tried array_merge and array_merge_recursive etc but those just add on the values to the end of the array I am tried to merge them into the same array key.
I think i need a foreach loop that checks if order_id = order_id from the second, and if it does push the items to the third array. However my problem is the arrays are not sorted by order_id so they may never be the same since the foreach loop would look through the array in the order of the array if that makes sense.