I Am posting this question as I didn't get a solution while searching here. Here is my question
I have an array coming after submitting data from the view page, its a list of product user has selected to book certain dates(start_date and end_date). like he might have selected 3 different products on the same date, or all the 3 products on different date starting date and return date.
Now I have an array in which I have all the products selected by a user with start_date and end_date and other product related information.
Before Storing these products as ORDERS, I need to check
If multiple products have same start_date and end_date, then it becomes one order.
If multiple products have different start_date and end_date, then it becomes different orders.
Now how will I check if these products have the same start_date and end_date or different?
for example.. this is an array
Array
(
[0] => Array
(
[product_id] => 15
[start_date] => 2019-05-15
[end_date] => 2019-05-16
[status] => in_stock
)
[1] => Array
(
[product_id] => 16
[start_date] => 2019-05-15
[end_date] => 2019-05-16
[status] => out_of_stock
)
[2] => Array
(
[product_id] => 17
[start_date] => 2019-05-17
[end_date] => 2019-05-18
[status] => in_stock
)
)
These are 3 different products, here 2 products are booked for same date product_id[15,16]-> so it becomes one Order.
And the other product_id number 17 becomes one second Order.
Edit...
I have added status to the array now, lets say i have 2 orders on same date product_id[15,16], now it has to sort based on two condition,
If multiple order have same start_date and end_date, then it becomes single order/array, which i have achieved by using accepted answer.
Now lets say after sorting i get an array in which i have 2 different products, one is in_stock and other is out_of_stock, now it should again become two different orders.
Please give some solution, as I am stuck here.