Ok. I think I have to change to another way. Is it possible to make another dimension in the array?
I have changed the function a little and add in other dates into the array. I have made a comment "// Newly Added".
PHP Code:
function unavailableDates(&$DB, $personnelId, $month, $coy) {
// Base on the ID, check with the individual schedule
$queryID = "SELECT individual_schedule_date FROM dms_individual_schedule WHERE personnel_id = $personnelId";
$rsID = $DB->Execute($queryID);
$arrID = $rsID->FetchRow();
// Remove the last 2 character (, ) from the string using substr
// Use explode to convert string into array
$dates = explode(', ', substr($arrID['individual_schedule_date'], 0, -2));
// Base on the Coy, check with the company schedule
// Newly Added
$queryCoy = "SELECT schedule_training_date FROM dms_company_schedule WHERE schedule_company = '$coy' AND schedule_training_date != ''";
$rsCoy = $DB->Execute($queryCoy);
$arrCoy = $rsCoy->FetchRow();
$datesCoy = explode(', ', substr($arrCoy['schedule_training_date'], 0, -2));
// Get the available dates for the specified month instead of the whole schedule
$availableDates = array();
foreach ($dates as $dateValue) {
if (substr($dateValue, 5, 2) == $month) {
$availableDates[] = $dateValue;
}
}
// Get the available dates for company for the specified month instead of the whole schedule
// Newly added
$availableCoyDates = array();
foreach ($datesCoy as $dateValueCoy) {
if (substr($dateValueCoy, 5, 2) == $month) {
$availableCoyDates[] = $dateValueCoy;
}
}
// Combine both the dates and place into one array
$availableDates_merge = array_merge($availableDates, $availableCoyDates);
return $availableDates_merge;
}
Thus, currently, the result is
Example, under the name "Tan Ah Lian". It's inclusive of two date that uses array_merge to combine the dates from two query.
Could I do it in a way that separate it? Like the below.