Jump to content

check array of dates are conecutive


Simmo

Recommended Posts

Hi,

A user selects week and a room to book. I put these into an array so I have now have an array of room numbers and dates.

 

I don't want them to book seperate holidays for one accommodation, I have mangaged to stop them booking a two week stay and they an extra week.  But I need a way to stop them booking two or three seperate two week holidays.  So basically I need to just give an error if the dates they have selected are not consecutive.

 

I have tried many variations of adding and subtracting 7 days  and comparing that in the array using a loop based on the room ids being the same.

 

I know the code below doesn't work but it gives an idea of how I been trying.

Also assume that the array has aan accomID and date seperated by a comma.

 

			 function search_break_in_consec_weeks($accomCountValidCheck, $accomID, $date){
			$allConsec = false;
			foreach ($accomCountValidCheck as $key=>$value){
				$varArray =  explode(', ', $value);
				$varDate =  $varArray[1];
				$varAccomID =  $varArray[0];
				if($accomID == $varAccomID && date("Y-m-d", strtotime($date)) == date("Y-m-d", strtotime($varDate ."+7 days")) || date("Y-m-d", strtotime($date)) == date("Y-m-d", strtotime($varDate ."-7 days"))){
					   $allConsec = true;
					   break;
					}else{
					   $allConsec = false;
					}
			}
			return $countStray;
		}
		foreach($accomCountValidCheck as $accomVal){
			$varArray =  explode(', ', $accomVal);
			$varAccomID  =  $varArray[0];
			$varDate=  $varArray[1];
			 $valReturnConsec = search_break_in_consec_weeks($accomCountValidCheck, $varAccomID, $varDate);
			if($valReturnConsec){echo '<b>'.$varAccomID.'</b>'. ' consec<br />';}
			if($valReturnConsec == false){echo $varAccomID .'not consec<br />';}

		}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.