Looks like the simplest way would to be to aggregate the counts into an array with the date as the key. You could then sort on the key and output the data however you desired.
Consider this:
$totalsByDate = [];
foreach ($array as $element) if (($date = strtotime($element->thedate)) and is_numeric($element->theadults)) {
$totalsByDate[$date] += $element->theadults;
}
ksort($totalsByDate);
foreach ($totalsByDate as $date => $total) {
echo "On " . date("Y-m-d", $date) . " there were " . $total " adults.\n";
}
You could also replace the ksort()
with krsort()
if you wanted the dates sorted in descending order.