For a reservation system, I want to see if the start and end date of a user input intersect with the start and end date stored in two arrays. One array holds all the start dates and one all the end dates. The values from the arrays have been fetched from the database before.
$startArray = [0 => "1.1.2021", 1 => "5.1.2021", 2 => "10.1.2021"];
$endArray = [0 => "6.1.2021", 1 => "8.1.2021", 2 => "13.1.2021"];
$startUser = "3.1.2021";
$endUser = "5.1.2021";
My goal is the see if the selection the user has made intersects with the selection from the array. I have tried this
foreach ($startArray as $key => $value) {
if (($startUser <= $endArray[$key]) && ($endUser >= $value)) {
//action;
}
That isn't working though. How would I best go about this?
EDIT: Date format is actually 2021-01-01. Both in the array as well as the user input.