I did run it in w3school.com, it return a string "06/12/2021,13/12/2021,20/12/2021,27/12/2021". It is what i want. I couldn't find any error in my code but it return only "12“ when i run in my website.That means the line "foreach (getWeekdays2m(date("Y"),date("m")) as $weekdayArray) “ has problem. Please kindly help.
<?php
$stringweekday = "";
function getWeekdays2m($y, $m) {
echo "1";
//$b = (int)$_POST[b];
$b = 1;
$m = $m+$b;
//$Day_of_class = $_POST[Day_of_class];
$Day_of_class = "monday";
$firstDay = "first $Day_of_class of $y-$m";
if ($b==1) {
echo "2";
return new DatePeriod(new DateTime($firstDay),DateInterval::createFromDateString('+1 week'),new DateTime("last day of $y-$m"));
}
else {
echo "3";
return new DatePeriod(new DateTime($firstDay),DateInterval::createFromDateString('+1 week'),new DateTime("last day of next month $y-$m"));
}
}
foreach (getWeekdays2m(date("Y"),date("m")) as $weekdayArray) {
echo "4";
if ($stringweekday == "") {
echo "5";
$stringweekday = $weekdayArray->format("d/m/Y");
}
else {
echo "6";
$stringweekday = $stringweekday.",".$weekdayArray->format("d/m/Y");
}
}
echo "7";
echo $stringweekday;
?>