mercredi 1 octobre 2014

How to merge date range in array


Vote count:

-1




I have some date ranges in array, and want to merge them. The result is a date range with the lowest start date and the highest end date. These are some samples in different cases. case 1:



$case1 = array(
array(
'start_date' => '2014-10-06',
'end_date' => '2014-10-23',
),
array(
'start_date' => '2014-10-10',
'end_date' => '2014-10-12',
),
array(
'start_date' => '2014-10-17',
'end_date' => '2014-10-19',
),
);

//expected
$res1 = array('start_date' => '2014-10-06', 'end_date' => '2014-10-23');


case 2:



$case2 = array(
array(
'start_date' => '2014-10-06',
'end_date' => '2014-10-23',
),
array(
'start_date' => '2014-09-10',
'end_date' => '2014-10-12',
),
array(
'start_date' => '2014-10-17',
'end_date' => '2014-10-19',
),
);

//expected
$res2 = array('start_date' => '2014-09-10', 'end_date' => '2014-10-23');


case 3:



$case3 = array(
array(
'start_date' => '2014-10-06',
'end_date' => '2014-10-23',
),
array(
'start_date' => '2014-10-10',
'end_date' => '2014-10-12',
),
array(
'start_date' => '2014-10-17',
'end_date' => '2014-11-12',
),
);

//expected
$res3 = array('start_date' => '2014-10-06', 'end_date' => '2014-11-12');


Your help is highly appreciated. Thank you guys



asked 1 min ago







How to merge date range in array

Aucun commentaire:

Enregistrer un commentaire