I have seen tons of questions that discuss portions of my question, but have been unable to work them into a solution. Hopefully someone can help me out.
I have two arrays, I'll call them Quantity and Shipping.
Here is Quantity:
Array(
[0] => Array(
[0] => 1
[1] => Fed-Ex
)
[1] => Array(
[0] => 2
[1] => USPS
)
[2] => Array(
[0] => 1
[1] => USPS-E
)
)
[0] is the quantity, and [1] is the name.
And here is Shipping:
Array(
[0] => Array(
[0] => 3
[1] => Fed-Ex
)
[1] => Array(
[0] => 1
[1] => USPS
)
[2] => Array(
[0] => 11
[1] => USPS-A
)
[3] => Array(
[0] => 10
[1] => USPS-E
)
)
[0] is the index, and [1] is the name.
I would like to combine them based on index 1 matches into something that looks like this. If there is no match I would like a 0 to be inserted instead (like in my USPS-A example).
I'll call it Master:
Array(
[0] => Array(
[0] => 3
[1] => Fed-Ex
[2] => 1
)
[1] => Array(
[0] => 1
[1] => USPS
[2] => 2
)
[2] => Array(
[0] => 11
[1] => USPS-A
[2] => 0
)
[3] => Array(
[0] => 10
[1] => USPS-E
[2] => 1
)
)
[0] is the index, [1] is the name, and [2] is the quantity.
Does anyone have any suggestions? I tried using nested foreach loops but I was ending up with duplicates even when I used break statements. Tried array_column and in_array as well but to no success.
Any help would be appreciated. Thank you.