R
R
Roman Makarov2016-02-02 01:25:48
PHP
Roman Makarov, 2016-02-02 01:25:48

How to split an array of dates into groups by week?

I have an array of dates

$array = [0 = > ['date' => unixDate, 'param' => 'val'], ..]

How can I group items by week? those. get an array of the form
$res = ['week1' => [], ..]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2016-02-02
@rmakarov

function splitByWeek($dots) {
    $splitted = [];

    foreach ($dots as $dot) {
        $week = date("YW", $dot['date']);
        $splitted[$week][] = $dot;
    }

    return $splitted;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question