Get Date Chunks of Month

Submitted by delickate on
How to get chunks of three dates on providing specific date of month? Here is a php code for that: $holidays = array('Sunday'); $result = chunks('2017-10-13', $holidays); echo "
"; print_r($result);

function chunks($inputDate, $holidays)
{
	$dayName  		= date('l',strtotime($inputDate));         //SANI: Getting Day name of date
	$lastDate 		= date('t',strtotime($inputDate));         //SANI: Getting Last Date of month
	$month    		= date('m',strtotime($inputDate));         //SANI: getting Month of date
	$year     		= date('Y',strtotime($inputDate));         //SANI: Getting Year of date
	
	$dateOuterLayer = array();
	$loopIndex  	= 1;
	$LayerIndex     = 0;

	$outerLayer     = 0;
	
	for($m=1; $m=$lastDate; $m++)                       //SANI: Loop through all dates of month
	{
		$monthDays = date("Y-m-d", strtotime("".$year."-".$month."-".$m.""));         
		
		if(in_array(date('l',strtotime($monthDays)), $holidays)) continue;        //SANI: Skip all holidays of month
		
		if($loopIndex == 1) $LayerIndex++;             //SANI: Setting up Outer loop index     
				
		$dateOuterLayer[$LayerIndex][$loopIndex-1] = $monthDays ;
		
		if($loopIndex == 3) $loopIndex = 0;            //SANI: Setting up Inner loop index
		
		$loopIndex++;
	}
	
	foreach($dateOuterLayer as $chunk)               //SANI: Loop through outer array
	{
		if(in_array($inputDate, $chunk))            //SANI: Check in which chunk that date exist.
		{
			return $chunk;                          //SANI: Return required chunk
		}
	}
	
	//SANI: complete array is: return $dateOuterLayer;
}