Super fast version
Date conversions are costly. I was disappointed by the performance so I tried to tune it a little for speed. It's more like a case study for optimization, but I'm going to leave it here because it's almost 3x faster than usual. It works by reducing the number of times date( ) being called.
function listDaysBetween($from,$till) {
if($till<$from) return[]; // handle the obvious empty case
$tsFrom = strtotime("$from 11:00"); // middle of first day
$tsTill = strtotime("$till 11:00"); // middle of last day
$tsDiff = $tsTill - $tsFrom; // seconds diff
$diff = round($tsDiff/86400); // days diff; output length
$ts = $tsFrom; // $ts will follow us along
$day = $from; // $day will scan the range
$days = [$day]; // put the first one in there
while($diff-->0) { // a disguised for-loop
$ts+=86400; // keep timestamp following
$d = (int)($day[8].$day[9]); // get the day part (fast)
if($d>27) { // at the end of each month,
$day = date("Y-m-d",$ts); // it's better to ask date()
}else{ // otherwise we do it faster
$d+=101; $d="$d"; // zero-padding to 2 digits
$day[8] = $d[1]; // direct character replace
$day[9] = $d[2]; // is faster than substr()
}
$days[] = $day; // build output array
}
return $days;
}
I hope you'll enjoy the nasty tricks. Tried many ways for many parts of this code, this version is a clear winner so far but I'm open for suggestions. (Apart from caching in a static variable for subsequent calls. That's cheating. I'd totally do it but still.)
Read more about this if you like.
NOTE: this function has no input control, you'll need at least some regex to avoid accidental endless loops when calling with bogus data. I omitted those lines for brevity.