Explanation inline & in comments!
/*public*/ function days($year, $month){
$days=array();
for($d=1; $d<=31; $d++) {
$time=mktime(12, 0, 0, $month, $d, $year);
// here check if weekday (date('w', $time)) is greater than sun (=0) and lower than sat (=6)
if(date('m', $time)==$month && date('w', $time)>0 && date('w', $time)<6) {
$days[]=date('Y-m-d H:i:s', $time);
}
}
return $days;
}
print_r(days(2018, 3));
// output:
// Array ( [0] => 2018-03-01 12:00:00 [1] => 2018-03-02 12:00:00 [2] => 2018-03-05 12:00:00 [3] => 2018-03-06 12:00:00 [4] => 2018-03-07 12:00:00 [5] => 2018-03-08 12:00:00 [6] => 2018-03-09 12:00:00 [7] => 2018-03-12 12:00:00 [8] => 2018-03-13 12:00:00 [9] => 2018-03-14 12:00:00 [10] => 2018-03-15 12:00:00 [11] => 2018-03-16 12:00:00 [12] => 2018-03-19 12:00:00 [13] => 2018-03-20 12:00:00 [14] => 2018-03-21 12:00:00 [15] => 2018-03-22 12:00:00 [16] => 2018-03-23 12:00:00 [17] => 2018-03-26 12:00:00 [18] => 2018-03-27 12:00:00 [19] => 2018-03-28 12:00:00 [20] => 2018-03-29 12:00:00 [21] => 2018-03-30 12:00:00 )