array(
[0] => 04.02.2013-03.03.2013
[1] => 04.03.2013-03.04.2013
[2] => 04.12.2013-03.01.2014
[3] => 04.01.2014-03.02.2014
[4] => 04.12.2014-03.01.2015
[5] => 04.01.2015-03.02.2015
[6] => 04.02.2015-03.03.2015
);
array(
[2013] => array(
[0] => 04.02-03.03,
[1] => 04.03-03.04,
[2] => 04.12-03.01
),
[2014] => array(
[0] => 04.01-03.02,
[1] => 04.12-03.01
),
[2014] => array(
[0] => 04.01-03.02,
[1] => 04.02-03.03
),
);
$result = [];
foreach ($sourceArray as $key=>$value) {
$dates = explode('-', $value);
$numbers = explode('.', $dates[0]);
$year = $numbers[2];
if (!isset($result[$year])) {
$result[$year] = [];
}
$result[$year][] = substr($dates[0], 0, 5) . '-' . substr($dates[0], 0, 5);
}
$arr1 = [
'04.02.2013-03.03.2013',
'04.03.2013-03.04.2013',
'04.12.2013-03.01.2014',
'04.01.2014-03.02.2014',
'04.12.2014-03.01.2015',
'04.01.2015-03.02.2015',
'04.02.2015-03.03.2015',
];
$result = [];
foreach ($arr as $r) {
$year = [];
if (preg_match('/.[0-9]{4}/', $r, $year)) {
$year = $year[0];
if (!isset($result[$year]) {
$result[$year] = [];
}
$result[$year][] = str_replace(".$year", '', $r);
}
}