So this is my code for set the date from selected date to auto set date excluding weekend (sat&sun) and holiday ( i put it in database ) :
function number_of_working_dates($from, $days) {
/* get holiday from database */
include('includes/config.php');
$sss = "SELECT tanggal_awal FROM libur_nasional GROUP BY tanggal_awal ASC";
$qqq = mysqli_query($konek,$sss);
$arr = array();
while ( $tam = mysqli_fetch_array($qqq)) {
$date = $tam['tanggal_awal'];
$reformat_date = date("Y-m-d", strtotime($date));
$arr[] = $reformat_date;
}
$array_date_2 = '"'.implode('", "' , $arr) . '"';
The output of implode()
is a list of dates:
"2018-08-09", "2018-08-10", "2018-08-15", "2018-08-17"
Then the continuation:
$holidayDays = [$array_date_2];
//$holidayDays = ["2018-08-09", "2018-08-10", "2018-08-15", "2018-08-17"]
$from = new DateTime($from);
$dates = [];
$dates[] = $from->format('Y-m-d');
**echo count($holidayDays);**
while ($days) {
$from->modify('+1 day');
if (!in_array($from->format('N'), $workingDays)) continue;
if (in_array($from->format('Y-m-d'), $holidayDays)) continue;
if (in_array($from->format('*-m-d'), $holidayDays)) continue;
$dates[] = $from->format('Y-m-d');
$days--;
}
return $dates;
}
When I count the "holidayDays" array using "count" it only shows 1 item, but when I hardcoded the date list like in the comment line it works and shows 4 items.
Can someone help me?