<?php
function gerarVencimentos
(DateTime
$dataInicial, array $intervalos): array { $datasVencimento = [];
foreach ($intervalos as $dias) {
$dataVencimento = clone $dataInicial;
$dataVencimento->modify("+{$dias} days");
$datasVencimento[] = $dataVencimento;
}
return $datasVencimento;
}
// Exemplo de uso
$dataInicial = new DateTime('2024-07-06');
$intervalos = [0, 30, 60, 90, 28, 42, 56];
$datasVencimento = gerarVencimentos($dataInicial, $intervalos);
foreach ($datasVencimento as $data) {
echo $data->format('Y-m-d') . PHP_EOL;
}
PD9waHAKCmZ1bmN0aW9uIGdlcmFyVmVuY2ltZW50b3MoRGF0ZVRpbWUgJGRhdGFJbmljaWFsLCBhcnJheSAkaW50ZXJ2YWxvcyk6IGFycmF5IHsKICAgICRkYXRhc1ZlbmNpbWVudG8gPSBbXTsKCiAgICBmb3JlYWNoICgkaW50ZXJ2YWxvcyBhcyAkZGlhcykgewogICAgICAgICRkYXRhVmVuY2ltZW50byA9IGNsb25lICRkYXRhSW5pY2lhbDsKICAgICAgICAkZGF0YVZlbmNpbWVudG8tPm1vZGlmeSgiK3skZGlhc30gZGF5cyIpOwogICAgICAgICRkYXRhc1ZlbmNpbWVudG9bXSA9ICRkYXRhVmVuY2ltZW50bzsKICAgIH0KCiAgICByZXR1cm4gJGRhdGFzVmVuY2ltZW50bzsKfQoKLy8gRXhlbXBsbyBkZSB1c28KJGRhdGFJbmljaWFsID0gbmV3IERhdGVUaW1lKCcyMDI0LTA3LTA2Jyk7CiRpbnRlcnZhbG9zID0gWzAsIDMwLCA2MCwgOTAsIDI4LCA0MiwgNTZdOwoKJGRhdGFzVmVuY2ltZW50byA9IGdlcmFyVmVuY2ltZW50b3MoJGRhdGFJbmljaWFsLCAkaW50ZXJ2YWxvcyk7Cgpmb3JlYWNoICgkZGF0YXNWZW5jaW1lbnRvIGFzICRkYXRhKSB7CiAgICBlY2hvICRkYXRhLT5mb3JtYXQoJ1ktbS1kJykgLiBQSFBfRU9MOwp9Cg==