What I am trying to do is get the date ($date\_before\_that\_expiry) which is $time\_to\_expiry (6) days before $distinct\_expiries (26-Oct-2017) in the format DD-MM-YYYY

However, if the returned date is is in array ($trading\_holiday\_array) then it should move the returned date ($date\_before\_that\_expiry) one day before. This is to be done recursively.

Eg: if I get a date 20-Oct-2017 initially it should return me 18-Oct-2017 and not 19th as 19-Oct-2017 is also a part of ($trading\_holiday\_array).

Here is the code I have put down but it goes into an infinite loop:

```
<?php
$distinct_expiries='26-Oct-2017';
$time_to_expiry=6;
$trading_holiday_array = array('19-Oct-2017', '20-Oct-2017');

$date_before_that_expiry = date('d-M-Y', strtotime("-$time_to_expiry days", strtotime($distinct_expiries)));

while(in_array($date_before_that_expiry, $trading_holiday_array)) {
$new_lookback= -(1+$time_to_expiry)." days";
$date_before_that_expiry = date('d-M-Y', strtotime("$new_lookback", strtotime($distinct_expiries)));

}
echo $date_before_that_expiry;

?>

```

Please assist.