title: How to sort array by months/weeks from given dataset in PHP
body: <p>Given a dataset from a database I want to get new arrays in a custom order.</p>
  <p>The dataset would look like this:</p>
  <pre><code> $dataset = [
  'val1' =&gt; ['202201' =&gt; '1', '202202' =&gt; '2', '202203' =&gt; '3', '202206' =&gt; '5', '202207' =&gt; '4'], 
  'val2' =&gt; ['202201' =&gt; '54', '202202' =&gt; '43', '202203' =&gt; '12']
  ]
  </code></pre>
  <p>As you can see val1, val2, etc. are ordered by year and weeknumber which are technically DateTime objects. I am able to output this dataset now to an array ordered by weeks.</p>
  <p>But I want to have a second array now, which aggregates these values by month like the following:</p>
  <pre><code>$perMonth = [
  '2022-01' =&gt; ['val1' =&gt; '6'], //Month 1 related week values added together
  '2022-02' =&gt; ['val1' =&gt; '9'] //Month 2 related week values added together
  ]
  </code></pre>
  <p>Do you have any ideas how can I approach this problem? I can't edit the database.
  Thanks for your help!</p>