Get Date Chunks of Month

How to get chunks of three dates on providing specific date of month? Here is a php code for that:
  1. $holidays = array('Sunday');
  2. $result = chunks('2017-10-13', $holidays);
  3.  
  4. echo "<pre>"; print_r($result);
  5.  
  6. function chunks($inputDate, $holidays)
  7. {
  8. $dayName = date('l',strtotime($inputDate)); //SANI: Getting Day name of date
  9. $lastDate = date('t',strtotime($inputDate)); //SANI: Getting Last Date of month
  10. $month = date('m',strtotime($inputDate)); //SANI: getting Month of date
  11. $year = date('Y',strtotime($inputDate)); //SANI: Getting Year of date
  12.  
  13. $dateOuterLayer = array();
  14. $loopIndex = 1;
  15. $LayerIndex = 0;
  16.  
  17. $outerLayer = 0;
  18.  
  19. for($m=1; $m<=$lastDate; $m++) //SANI: Loop through all dates of month
  20. {
  21. $monthDays = date("Y-m-d", strtotime("".$year."-".$month."-".$m.""));
  22.  
  23. if(in_array(date('l',strtotime($monthDays)), $holidays)) continue; //SANI: Skip all holidays of month
  24.  
  25. if($loopIndex == 1) $LayerIndex++; //SANI: Setting up Outer loop index
  26.  
  27. $dateOuterLayer[$LayerIndex][$loopIndex-1] = $monthDays ;
  28.  
  29. if($loopIndex == 3) $loopIndex = 0; //SANI: Setting up Inner loop index
  30.  
  31. $loopIndex++;
  32. }
  33.  
  34. foreach($dateOuterLayer as $chunk) //SANI: Loop through outer array
  35. {
  36. if(in_array($inputDate, $chunk)) //SANI: Check in which chunk that date exist.
  37. {
  38. return $chunk; //SANI: Return required chunk
  39. }
  40. }
  41.  
  42. //SANI: complete array is: return $dateOuterLayer;
  43. }

Add new comment