fork(1) download
  1. <?php
  2.  
  3. $arr = [
  4. "01/02/2015",
  5. "02/02/2015",
  6. "03/02/2015",
  7. "04/02/2015",
  8. "05/02/2015",
  9. "09/02/2015",
  10. "10/02/2015",
  11. "11/02/2015",
  12. "12/02/2015",
  13. ];
  14.  
  15. //complexidade O(n)
  16. function processaDias($arrDias) {
  17. $index = 0;
  18. $dia_anterior = "";
  19. $ret = [];
  20. foreach($arrDias as $dia) {
  21. if ($dia_anterior === "") {
  22. $ret[$index][] = $dia;
  23. $dia_anterior = $dia;
  24. continue;
  25. }
  26.  
  27. $d1 = DateTime::createFromFormat("d/m/Y", $dia_anterior);
  28. $d2 = DateTime::createFromFormat("d/m/Y", $dia);
  29.  
  30. $diff = $d2->diff($d1);
  31.  
  32. if($diff->format("%d") !== "1") {
  33. $index++;
  34. }
  35.  
  36. $ret[$index][] = $dia;
  37.  
  38. $dia_anterior = $dia;
  39. }
  40.  
  41. return $ret;
  42. }
  43.  
  44. $res = processaDias($arr);
  45.  
  46. var_dump($res);
Success #stdin #stdout 0.03s 24448KB
stdin
Standard input is empty
stdout
array(2) {
  [0]=>
  array(5) {
    [0]=>
    string(10) "01/02/2015"
    [1]=>
    string(10) "02/02/2015"
    [2]=>
    string(10) "03/02/2015"
    [3]=>
    string(10) "04/02/2015"
    [4]=>
    string(10) "05/02/2015"
  }
  [1]=>
  array(4) {
    [0]=>
    string(10) "09/02/2015"
    [1]=>
    string(10) "10/02/2015"
    [2]=>
    string(10) "11/02/2015"
    [3]=>
    string(10) "12/02/2015"
  }
}