I have two arrays :
$data = Array
(
[0] => Array
(
[StartTime] => 13:00:00
[EndTime] => 14:00:00
)
[1] => Array
(
[StartTime] => 16:00:00
[EndTime] => 16:30:00
)
)
$slot = Array
(
[0] => 09:00:00
[1] => 09:30:00
[2] => 10:00:00
[3] => 10:30:00
[4] => 11:00:00
[5] => 11:30:00
[6] => 12:00:00
[7] => 12:30:00
[8] => 13:00:00
[9] => 13:30:00
[10] => 14:00:00
[11] => 14:30:00
[12] => 15:00:00
[13] => 15:30:00
[14] => 16:00:00
[15] => 16:30:00
[16] => 17:00:00
[17] => 17:30:00
)
now $data is my blocked time slots. and $slot is my total time slots. i want to match blocked time slots against total slots and get the available time slots.
I am trying through this loops but its not working.
for($i=0;$i<count($slot)-1;$i++)
{
if(count($data)==0)
{
$result[] = date('H:i',strtotime($slot[$i]))."-".date('H:i',strtotime($slot[$i+1]));
}
else
{
for($j=0;$j<count($data);$j++)
{
if(strtotime($slot[$i]) >= strtotime($data[$j]['StartTime']) && strtotime($slot[$i]) <= strtotime($data[$j]['EndTime']))
{
//echo "busy slot so it should not be in result.";
}
else
{
$result[] = date('H:i',strtotime($slot[$i]))."-".date('H:i',strtotime($slot[$i+1]));
}
}
}
}
But its giving the result twice. and not filtering the busy records properly.
Can anyone please help me to find out my mistake and get the correct available time slots ?