title: How to sort an array by date key?
body: <p>I have an array with key in "Y-m" format. I want to sort this array based on this key.</p>
  
  <pre><code>$array = array(
    "2018-10" =&gt; 239,
    "2018-11" =&gt; 264,
    "2018-12" =&gt; 237,
    "2019-01" =&gt; 211,
    "2019-04" =&gt; "0",
    "2019-03" =&gt; "0",
    "2019-02" =&gt; "0"
  );
  </code></pre>
  
  <p>My final result should be like:</p>
  
  <pre><code>$array = array(
    "2019-04" =&gt; "0",
    "2019-03" =&gt; "0",
    "2019-02" =&gt; "0",
    "2019-01" =&gt; 211,
    "2018-12" =&gt; 237,
    "2018-11" =&gt; 264,
    "2018-10" =&gt; 239
  );
  </code></pre>
  
  <p>This is the code so far I have tried.</p>
  
  <pre><code>$sorter = function($a, $b) {
              if (strtotime($a) == strtotime($b)) {
                  return 0;
              }
              return (strtotime($a) &lt; strtotime($b)) ? -1 : 1;
          };
  
          uksort($array, $sorter);
  </code></pre>