3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * step 1: create benchmark array * containing all consecutive dates from $start */ $start = '2019-10-27 16:30:00'; $days = 14; // total number of days (including $start) $dateObj = new DateTimeImmutable($start); $benchmarkDates[] = $dateObj->format('Y-m-d H:i:s'); // store the first bench date for ($i = 1; $i < $days; $i++) { $period = 'P' . $i . 'D'; $interval = new DateInterval($period); $dateObj0 = $dateObj->add($interval); $benchmarkDates[] = $dateObj0->format('Y-m-d H:i:s'); // store the next bench date } /* * create dummy array mimicking the OP's presented structure * create date gaps */ $start = '2019-10-27 16:30:00'; $days = 14; // total number of days (including $start) $dateObj = new DateTimeImmutable($start); $subject[0][] = ['datum' => $dateObj]; // store the first object for ($i = 2; $i < $days; $i += 2) { $period = 'P' . $i . 'D'; $interval = new DateInterval($period); $dateObj0 = $dateObj->add($interval); $subject[$i / 2][] = ['datum' => $dateObj0]; // store subsequent objects } /* step 2: get dates from subject array ($subject). */ foreach ($subject as $key => $value) { foreach ($value as $key => $value) { $subjectDates[] = $value['datum']->format('Y-m-d H:i:s'); // store dates } } /* * step 3: find / store missing dates * check subject against benchmark */ foreach($benchmarkDates as $key => $value) { if(!in_array($value, $subjectDates)) { $missingDates[] = $value; } } echo 'benchmark array:' . "\r\n"; print_r($benchmarkDates); echo 'subject array:' . "\r\n";; print_r($subjectDates); echo 'missing dates:' . "\r\n";; print_r($missingDates);

preferences:
32.15 ms | 409 KiB | 6 Q