how can i store the values inside a loop in array and return as JSON in yii2.
I have problem with this code:
$start = date("Y/m/d");
$interval = DateInterval::createFromDateString('1 month');
$end = date('Y/m/d', strtotime(sprintf("+%d months", $loanMonths)));
$periods = new DatePeriod(new DateTime($start), $interval, new DateTime($end));
$array = array();
foreach($periods as $period){
print_r(date('Y-F', strtotime($period->format('Y-m')))); echo "<br>";
}
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return $period;