-3

I have an array with start date and end date. Now I want to save the individual days between the given days in an array.

Array
(
[0] => Array
    (
        [start] => 2019-02-16
        [end] => 2019-02-23
    )

[1] => Array
    (
        [start] => 2019-03-15
        [end] => 2019-03-17
    )

[2] => Array
    (
        [start] => 2019-03-23
        [end] => 2019-03-24
    )

[3] => Array
    (
        [start] => 2019-03-27
        [end] => 2019-03-29
    )

[4] => Array
    (
        [start] => 2019-04-17
        [end] => 2019-04-21
    )
)

That should be the result: (only the days in "between")

Array
( 
 '2019-03-16',
 '2019-03-28',
 '2019-04-18',
 '2019-04-19',
 '2019-04-20'
)

How can I loop through the array?

Aubin
  • 14,617
  • 9
  • 61
  • 84
SteveO24
  • 9
  • 1
  • 1
    You haven't asked a question. What's the problem? – Alex Howansky Mar 22 '19 at 15:14
  • 1
    I'd recommend you to take a look at this: https://stackoverflow.com/help/how-to-ask – maio290 Mar 22 '19 at 15:14
  • actually u are saying date u need date between 2 dates, like `[start] => 2019-03-23 [end] => 2019-03-24` u have 0 days bw these 2 dates – devpro Mar 22 '19 at 15:15
  • Possible duplicate of [PHP: Return all dates between two dates in an array](https://stackoverflow.com/questions/4312439/php-return-all-dates-between-two-dates-in-an-array) – devpro Mar 22 '19 at 15:21

1 Answers1

2

Apply this to each couple of dates and merge into array:

$from = DateTime::createFromFormat('Y-m-d', '2019-02-16');
$from->add(new DateInterval('P1D'));
$to = DateTime::createFromFormat('Y-m-d', '2019-02-23');
$dates = iterator_to_array( new \DatePeriod( $from ), new \DateInterval( 'P1D' ), $to ) );
Elanochecer
  • 600
  • 3
  • 8