I have this kind of array data:
array:4 [
0 => array:7 [
"menu_id" => 1
"menu_name" => "Cheese Burger"
"menu_price" => "100.00"
"modItem" => array:2 [
0 => array:3 [
"id" => 62
"name" => "Regular Coke"
"price" => "50.00"
]
1 => array:3 [
"id" => 79
"name" => "Small Fries"
"price" => "10.00"
]
]
"addOnItem" => array:2 [
0 => array:3 [
"id" => 1
"name" => "Ice Cream"
"price" => "30.00"
]
1 => array:3 [
"id" => 49
"name" => "Tuna Pie"
"price" => "20.00"
]
]
"qty" => "1"
"special_instructions" => "this is a test special instruction"
]
1 => array:5 [
"menu_id" => 8
"menu_name" => "Regular Yum Burger"
"menu_price" => "50.00"
"qty" => "1"
"special_instructions" => ""
]
2 => array:5 [
"menu_id" => 6
"menu_name" => "Coke"
"menu_price" => "50.00"
"qty" => "1"
"special_instructions" => ""
]
3 => array:5 [
"menu_id" => 6
"menu_name" => "Coke"
"menu_price" => "50.00"
"qty" => "2"
"special_instructions" => ""
]
]
As you can see, the Coke is repeating and, i want to combine their qty and output a new array. So the output should be like this:
array:4 [
0 => array:7 [
"menu_id" => 1
"menu_name" => "Cheese Burger"
"menu_price" => "100.00"
"modItem" => array:2 [
0 => array:3 [
"id" => 62
"name" => "Regular Coke"
"price" => "50.00"
]
1 => array:3 [
"id" => 79
"name" => "Small Fries"
"price" => "10.00"
]
]
"addOnItem" => array:2 [
0 => array:3 [
"id" => 1
"name" => "Ice Cream"
"price" => "30.00"
]
1 => array:3 [
"id" => 49
"name" => "Tuna Pie"
"price" => "20.00"
]
]
"qty" => "1"
"special_instructions" => "this is a test special instruction"
]
1 => array:5 [
"menu_id" => 8
"menu_name" => "Regular Yum Burger"
"menu_price" => "50.00"
"qty" => "1"
"special_instructions" => ""
]
2 => array:5 [
"menu_id" => 6
"menu_name" => "Coke"
"menu_price" => "50.00"
"qty" => "3"
"special_instructions" => ""
]
]
The qty becomes 3 because I added together their qty key.
Take note that there will be times that the array key will have a modItem and addOnItem key. These will need to be checked too if these are repeating and have existing values with the other keys.
So basically if an array key has the same data within that single array, they will be combined and their quantity will be added up together.
Apologies if i didn't explain this properly as I am having difficulty explaing it, but feel free to leave a question.
Thanks in advance!