3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json='[{"from":"2019-07-22 09:00:00","to":"2019-07-22 11:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Close"},{"from":"2019-07-22 07:00:00","to":"2019-07-22 08:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Close"},{"from":"2019-07-22 07:00:00","to":"2019-07-22 08:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Open"},{"from":"2019-07-22 20:00:00","to":"2019-07-22 22:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Open"},{"from":"2019-07-22 11:00:00","to":"2019-07-22 17:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Open"},{"from":"2019-07-22 20:00:00","to":"2019-07-22 22:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Close"},{"from":"2019-07-22 07:00:00","to":"2019-07-22 15:00:00","rendering":"background","resource":"3529","backgroundColor":"#660000","purpose":"Close"}]'; //var_export(json_decode($json, true)); foreach (json_decode($json, true) as $i => $entry) { if (!$i) { $result[] = $entry; } else { foreach ($result as $stored) { if (($entry['from'] >= $stored['from'] && $entry['from'] < $stored['to']) || ($entry['to'] > $stored['from'] && $entry['to'] <= $stored['to'])) { continue 2; } } $result[] = $entry; } } var_export($result);
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
array ( 0 => array ( 'from' => '2019-07-22 09:00:00', 'to' => '2019-07-22 11:00:00', 'rendering' => 'background', 'resource' => '3529', 'backgroundColor' => '#660000', 'purpose' => 'Close', ), 1 => array ( 'from' => '2019-07-22 07:00:00', 'to' => '2019-07-22 08:00:00', 'rendering' => 'background', 'resource' => '3529', 'backgroundColor' => '#660000', 'purpose' => 'Close', ), 2 => array ( 'from' => '2019-07-22 20:00:00', 'to' => '2019-07-22 22:00:00', 'rendering' => 'background', 'resource' => '3529', 'backgroundColor' => '#660000', 'purpose' => 'Open', ), 3 => array ( 'from' => '2019-07-22 11:00:00', 'to' => '2019-07-22 17:00:00', 'rendering' => 'background', 'resource' => '3529', 'backgroundColor' => '#660000', 'purpose' => 'Open', ), )

preferences:
175.72 ms | 410 KiB | 5 Q