In php I made an array that looks like this:
array(2) {
[0]=>
array(6) {
["ID"]=>
string(1) "1"
["Time_start"]=>
string(8) "10:00:00"
["Time_stop"]=>
string(8) "10:30:00"
["Zipcode"]=>
string(6) "5652AR"
["Distance_original"]=>
string(2) "26"
["Distance"]=>
string(2) "30"
}
[1]=>
array(6) {
["ID"]=>
string(1) "2"
["Time_start"]=>
string(8) "13:00:00"
["Time_stop"]=>
string(8) "13:15:00"
["Zipcode"]=>
string(6) "5702ST"
["Distance_original"]=>
string(2) "12"
["Distance"]=>
string(2) "15"
}
}
Array looks like this:
$klanten[$i]['Time_start'] $klanten[$i]['Time_stop']
etc.
The array will contain more times in the future. Now I generate times in quarter of hours like this:
$times_array = hoursRange( 28800, 75600, 900, 'H:i');
foreach($times_array as $quarter) {
echo $quarter.'<br>';
}
Result: 08:00 08:15 08:30 08:45 09:00 09:15 etc. etc.
What I want to do, is generate the times like above, but without the times that are in "Time_start" and "Time_stop" (and between) in the array. How can I "remove" those times?
I guess i have to do something like this, to compare the times:
$start_time = strtotime($Time_start);
$end_time = strtotime($Time_stop);
And compare it with $quarter. But i don't know how to check each time with the time in the array (and how to check if it is a time between start- and endtime)
UPDATE: added the function hoursRange (it generates the quarter of hours)
Function hoursRange:
function hoursRange( $lower = 28800, $upper = 75600, $step = 900, $format = '' ) {
$times = array();
if ( empty( $format ) ) {
$format = 'g:i a';
}
foreach ( range( $lower, $upper, $step ) as $increment ) {
$increment = gmdate( 'H:i', $increment );
list( $hour, $minutes ) = explode( ':', $increment );
$date = new DateTime( $hour . ':' . $minutes );
$times[(string) $increment] = $date->format( $format );
}
return $times;
}
UPDATE 2:
I have this now:
$times_array = hoursRange( 28800, 75600, 900, 'H:i:s');
foreach($times_array as $quarter) {
$Time_start = array_column($klanten, 'Time_start');
$Time_stop = array_column($klanten, 'Time_stop');
for($i=0; $i < count($Time_start); $i++)
{
$date1 = DateTime::createFromFormat('H:i:s', $quarter);
$date2 = DateTime::createFromFormat('H:i:s', $Time_start[$i]);
$date3 = DateTime::createFromFormat('H:i:s', $Time_stop[$i]);
if ($date1 < $date2 && $date1 > $date3)
{
//echo $quarter;
}
else{
echo $quarter.'<br>';
}
}
Result: It generates all times two times now.