更新时间:2023-02-26 20:07:56
基本解决方案(可能不是***的解决方案,但至少是一个开始)
Basic solution (maybe not the best, but at least a start)
这个想法:从工作日开始到工作日结束,做一系列5分钟的练习.用0
填充它.每次进行约会时,将其放置在5分钟内,并以1
的形式放置在数组中.现在,您可以按块知道每个人是否有空.
The idea: make an array of 5-minute blocks from workday-start to workday end. Fill it with 0
. Every time an appointment is made, put it in 5-minute blocks and put it in the array as 1
. Now you know per block if someone is available.
//working hours
$start='10:45:00';
$end='18:45:00';
$start=strtotime($start);
$end=strtotime($end);
//end-start divided by 300 sec to create a 5 min block
$timesegments=($end-$start)/300;
//create the blocks-array
$blocks=array_fill_keys(range(0,$timesegments,5),0);
//an appointment
$app_start='10:45:00';
$app_end='11:00:00';
//make 5 minute blocks (note that workday start is 0!)
$app_start=(strtotime($app_start)-$start)/300;
$app_end=(strtotime($app_end)-$start)/300;
//put it in the blocks-array (+2 for 10 minute break)
for($i=$app_start;$i<$app_end+2;++$i){
$blocks[$i]=1;
}
echo '<pre>'.print_r($blocks,true).'</pre>';
这是非常基本的,没有任何检查,但我希望您可以使用它.
This is very basic and without any checks, but I hope you can use it.