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/>'; }

preferences:
55.29 ms | 404 KiB | 5 Q