3v4l.org

run code in 300+ PHP versions simultaneously
<?php $firstArray = array( array('startDate' => '05-05-2016', 'endDate' => '10-05-2016'), array('startDate' => '05-06-2016', 'endDate' => '10-07-2016'), array('startDate' => '05-08-2016', 'endDate' => '10-11-2016') ); $secondArray = array(array('date' => '07-05-2016'), array('date' => '12-07-2016'), array('date' => '12-11-2016')); function find_match($index){ global $firstArray, $secondArray; foreach($secondArray as $date){ if(strtotime($date['date']) > strtotime($firstArray[$index]['startDate']) && strtotime($date['date']) < strtotime($firstArray[$index]['endDate'])) return $date['date']; } return null; } foreach($firstArray as $key => $st_dates){ $date = find_match($key); echo ($date != null) ? $date : "No match Found."; echo '<br/>'; }
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.21, 7.0.0 - 7.0.20, 7.1.0 - 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
07-05-2016<br/>No match Found.<br/>No match Found.<br/>

preferences:
169.91 ms | 404 KiB | 241 Q