fork(2) download
  1. <?php
  2.  
  3. function parcelas($data, $numero = 12)
  4. {
  5. $parc = array();
  6. $parc[] = $data;
  7. list($ano, $mes, $dia) = explode("-", $data);
  8. for($i = 1; $i < $numero;$i++)
  9. {
  10. $mes++;
  11. if ((int)$mes == 13)
  12. {
  13. $ano++;
  14. $mes = 1;
  15. }
  16. $tira = $dia;
  17. while (!checkdate($mes, $tira, $ano))
  18. {
  19. $tira--;
  20. }
  21. $parc[] = sprintf("%02d-%02d-%02d", $ano, $mes, $tira);
  22. }
  23. return $parc;
  24. }
  25.  
  26.  
  27. $data = "2017-01-31";
  28.  
  29. var_dump(parcelas($data, 12));
Success #stdin #stdout 0.02s 52488KB
stdin
Standard input is empty
stdout
array(12) {
  [0]=>
  string(10) "2017-01-31"
  [1]=>
  string(10) "2017-02-28"
  [2]=>
  string(10) "2017-03-31"
  [3]=>
  string(10) "2017-04-30"
  [4]=>
  string(10) "2017-05-31"
  [5]=>
  string(10) "2017-06-30"
  [6]=>
  string(10) "2017-07-31"
  [7]=>
  string(10) "2017-08-31"
  [8]=>
  string(10) "2017-09-30"
  [9]=>
  string(10) "2017-10-31"
  [10]=>
  string(10) "2017-11-30"
  [11]=>
  string(10) "2017-12-31"
}