PHP code example of penance316 / merger

1. Go to this page and download the library: Download penance316/merger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

penance316 / merger example snippets



// Each date pair should consist of [earlierDate, laterDate].

$dates = [
    [new DateTime('2019-04-01'), new DateTime('2019-05-01')],
    [new DateTime('2019-05-01'), new DateTime('2019-06-01')],
    [new DateTime('2019-06-01'), new DateTime('2019-07-01')],
    [new DateTime('2019-07-01'), new DateTime('2019-08-01')],
    [new DateTime('2019-08-01'), new DateTime('2019-09-01')],
];

print_r(DateMerger::mergeRanges($dates));

// Output
// Array
// (
//     [0] => Array
//         (
//             [0] => DateTime Object
//                 (
//                     [date] => 2019-04-01 00:00:00.000000
//                     [timezone_type] => 3
//                     [timezone] => Europe/London
//                 )
// 
//             [1] => DateTime Object
//                 (
//                     [date] => 2019-09-01 00:00:00.000000
//                     [timezone_type] => 3
//                     [timezone] => Europe/London
//                 )
//
//         )
//
// )