I have the following code:
$months = array();
$numJoin = date("n",strtotime($me['joinTime']));
$numLast = date('n', strtotime('Dec 31'));
$numCurrent = date("n",strtotime('2016-06-01'));
array_push($months, date("F", strtotime($me['joinTime'])));
for($i = ($numJoin + 1); $i <= $numLast; $i++) {
if($numCurrent>$numJoin) {
$dateObj = date_create_from_format('!m', $i);
array_push($months, $dateObj->format('F'));
}
$numCurrent= -1;
}
What I'm trying to do here is to add the array that starts up in the current month and store the previous months in the array, for example, for example:
Beginning of the month → May June starts → I add June to the array (now I should have May and June in the array).
July starts -> I add July to the array (now I should have May, June and July in the array).
How can i do this? The current solution only works for +1 month. I can not add more than 1 month: /
PS A new element should be added only at the entrance of a new month, and the previous contents of the array should be saved ...