<?php
function pushEveryThreeMonths($originalArray) {
$newArray = [];
$interval = new DateInterval('P3M');
$startDate = new DateTime(); // current date and time
foreach ($originalArray as $element) {
$newArray[] = $element; // push the element to the new array
// Add three months to the start date
$startDate->add($interval);
// Check if the start date is in the future
if ($startDate > new DateTime()) {
break; // exit the loop if it's in the future
}
}
return $newArray;
}
// Example usage:
$originalArray = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'];
$newArray = pushEveryThreeMonths($originalArray);
// Output the new array
print_r($newArray);