I have this array data:
array:3 [
0 => array:5 [
"menu_id" => 7
"menu_name" => "Kasagbutan Meals"
"menu_price" => "100.00"
"qty" => "1"
"special_instructions" => ""
]
1 => array:5 [
"menu_id" => 7
"menu_name" => "Kasagbutan Meals"
"menu_price" => "100.00"
"qty" => "1"
"special_instructions" => ""
]
2 => array:5 [
"menu_id" => 6
"menu_name" => "Coke"
"menu_price" => "50.00"
"qty" => "1"
"special_instructions" => ""
]
]
When I ran it with array_unique()
, the data becomes like this:
array:2 [
0 => array:5 [
"menu_id" => 7
"menu_name" => "Kasagbutan Meals"
"menu_price" => "100.00"
"qty" => "1"
"special_instructions" => ""
]
2 => array:5 [
"menu_id" => 6
"menu_name" => "Coke"
"menu_price" => "50.00"
"qty" => "1"
"special_instructions" => ""
]
]
How can I add the qty
before it reduces the array? I want to add the qty
of the removed array item. So basically, the ideal array result should be like this:
array:2 [
0 => array:5 [
"menu_id" => 7
"menu_name" => "Kasagbutan Meals"
"menu_price" => "100.00"
"qty" => "2" ----> THIS BECOMES 2 BECAUSE THE OTHER ITEM HAS A QTY OF 1.
"special_instructions" => ""
]
2 => array:5 [
"menu_id" => 6
"menu_name" => "Coke"
"menu_price" => "50.00"
"qty" => "1"
"special_instructions" => ""
]
]