Convert consecutive qualifying values into hyphenated expressions in a 2d array

54 Views Asked by At

I have the following example array

$workerHoliday = array
(
array("john","2018-12-24 1","2018-12-25 0","2018-12-26 0","2018-12-27 1","2018-12-28 ","2018-12-31 1"), // 12.29 and 12.30 are weekends
array("mark","2018-12-14 1","2018-12-17 1","2018-12-18 1"), // 12.15 and 12.16  are weekends .
array("ben","2018-11-05 1","2018-11-06 1","2018-11-12 1","2018-11-13 1")
);     

This contains the workers name and a date where he has requested a vacation, marked with 1 .So "2018-12-24 1" means that he wants to be free on that day . "2018-12-25 0" The Zero means that , that day is a holiday , so the worker is usually free on that day . The weekends and the holidays should be filtered out. And if the main idea of the worker is , to be free from 12.24 to the 12.31 , we should get "2018-12-24 - 2018-12-31 1" .Also a worker can have multiple vacation requests in 1 array (look at ben). So at the end the array should look like this.

 $workerHoliday = array
  (
  array("john","2018-12-24 - 2018-12-31 1"), 
  array("mark","2018-12-14 - 2018-12-18 1"), 
  array("ben","2018-11-05 - 2018-11-06 1","2018-11-12 - 2018-11-13 1")
  );     
0

There are 0 best solutions below