If you are grouping your result set into three categories - This week, Next week and Upcoming - you just need to know is the start of the next week and the week after. You can then iterate over your result set, compare and group accordingly.
Judging from your comments above you are starting the week on Monday, so:
$dateTime = new DateTime('next monday');
$weekStartNext = $dateTime->format('Y-m-d H:i:s');
$weekStartAfter = $dateTime->add(new DateInterval('P7D'))->format('Y-m-d H:i:s');
You now have ISO8601 format datetime strings for the next Monday and the Monday after. So, given a result set like this:
$rows = [
[
'name' => 'Sunday 7th June',
'start_date' => '2015-06-07 00:00:00',
],
[
'name' => 'Monday 8th June',
'start_date' => '2015-06-08 00:00:00',
],
[
'name' => 'Friday 12th June',
'start_date' => '2015-06-12 00:00:00',
],
[
'name' => 'Sunday 14th June',
'start_date' => '2015-06-14 00:00:00',
],
[
'name' => 'Monday 15th June',
'start_date' => '2015-06-15 00:00:00',
],
[
'name' => 'Sunday 21st June',
'start_date' => '2015-06-21 00:00:00',
],
[
'name' => 'Tuesday 30th June',
'start_date' => '2015-06-30 00:00:00',
],
[
'name' => 'Wednesday 1st July',
'start_date' => '2015-07-01 00:00:00',
],
];
You can do simple string comparison on the row dates, like so:
$sorted = [];
foreach ($rows as $row) {
$startDate = $row['start_date'];
if ($startDate < $weekStartNext) {
$sorted['This week'][] = $row;
} elseif ($startDate >= $weekStartNext && $startDate < $weekStartAfter) {
$sorted['Next week'][] = $row;
} else {
$sorted['Upcoming'][] = $row;
}
}
print_r($sorted);
This yields:
Array
(
[This week] => Array
(
[0] => Array
(
[name] => Sunday 7th June
[start_date] => 2015-06-07 00:00:00
)
)
[Next week] => Array
(
[0] => Array
(
[name] => Monday 8th June
[start_date] => 2015-06-08 00:00:00
)
[1] => Array
(
[name] => Friday 12th June
[start_date] => 2015-06-12 00:00:00
)
[2] => Array
(
[name] => Sunday 14th June
[start_date] => 2015-06-14 00:00:00
)
)
[Upcoming] => Array
(
[0] => Array
(
[name] => Monday 15th June
[start_date] => 2015-06-15 00:00:00
)
[1] => Array
(
[name] => Sunday 21st June
[start_date] => 2015-06-21 00:00:00
)
[2] => Array
(
[name] => Tuesday 30th June
[start_date] => 2015-06-30 00:00:00
)
[3] => Array
(
[name] => Wednesday 1st July
[start_date] => 2015-07-01 00:00:00
)
)
)
Hope this helps :)