I have an array where I store an ID and for every ID there's an array that holds a start and end value. My goal is to check if the start value is smaller than the end value of the item that comes before it in the array.
This works but my loop doesn't care about the ID's, I need a way to do this per ID
Here's what my array looks like:
Array
(
[892] => Array
(
[41] => Array
(
[0] => Array
(
[start] => 0930
[end] => 1200
)
)
)
[897] => Array
(
[41] => Array
(
[0] => Array
(
[start] => 1000
[end] => 1230
)
)
)
[898] => Array
(
[41] => Array
(
[0] => Array
(
[start] => 1100
[end] => 1300
)
)
)
[901] => Array
(
[52] => Array
(
[0] => Array
(
[start] => 0930
[end] => 1030
)
)
)
[903] => Array
(
[52] => Array
(
[0] => Array
(
[start] => 0930
[end] => 1030
)
)
)
[904] => Array
(
[41] => Array
(
[0] => Array
(
[start] => 1000
[end] => 1230
)
)
)
)
And this is what my loop looks like:
$foundOverlap = false;
$prevEnd = null;
foreach($slots as $s){
$startHour = $s[0]['start'];
$endHour = $s[0]['end'];
echo $startHour . '<br>';
echo $endHour . '<br>';
if($prevEnd !== null && $startHour < $prevEnd){
$foundOverlap = true;
$counter++;
}
if($foundOverlap){
echo 'overlap <br>';
}else{
echo 'no overlap <br>';
}
$prevEnd = $endHour;
}
As a result I get No overlap(good), overlap(good), overlap(good), overlap(BAD!) this should be no overlap. But it says overlap because It checks with the previous array item doesn't care what the attractieID is...
Anyone please knows how I can fix this?
I would be soooo thankful!!
Thanks in advance!