title: Grouping array items based on string value
body: <p>I am trying to group an array by <code>sport</code>. It could be <code>n</code> number of sports. Finally, then create a new array with it. Is there an efficient way to this without going overkill?</p>
  
  <pre><code>$sports = [
      ['sport' =&gt; 'soccer', 'id' =&gt; 97487];
      ['sport' =&gt; 'soccer', 'id' =&gt; 244800];
      ['sport' =&gt; 'soccer', 'id' =&gt; 258740];
      ['sport' =&gt; 'basketball', 'id' =&gt; 147884];
      ['sport' =&gt; 'baseball', 'id' =&gt; 222240];
      ['sport' =&gt; 'baseball', 'id' =&gt; 222245];
  ];
  </code></pre>
  
  <p>Initial array:</p>
  
  <pre><code>array(6) {
    [0]=&gt;
    array(2) {
      ["sport"]=&gt;
      string(6) "soccer"
      ["id"]=&gt;
      int(97487)
    }
    [1]=&gt;
    array(2) {
      ["sport"]=&gt;
      string(6) "soccer"
      ["id"]=&gt;
      int(244800)
    }
    [2]=&gt;
    array(2) {
      ["sport"]=&gt;
      string(6) "soccer"
      ["id"]=&gt;
      int(258740)
    }
    [3]=&gt;
    array(2) {
      ["sport"]=&gt;
      string(10) "basketball"
      ["id"]=&gt;
      int(147884)
    }
    [4]=&gt;
    array(2) {
      ["sport"]=&gt;
      string(8) "baseball"
      ["id"]=&gt;
      int(222240)
    }
    [5]=&gt;
    array(2) {
      ["sport"]=&gt;
      string(8) "baseball"
      ["id"]=&gt;
      int(222245)
    }
  }
  </code></pre>
  
  <p>Desired results:</p>
  
  <pre><code>array(3) 
  {
      [0]=&gt;
      array(3) {
          [0]=&gt;
          array(2) {
            ["sport"]=&gt;
            string(6) "soccer"
            ["id"]=&gt;
            int(97487)
          }
          [1]=&gt;
          array(2) {
            ["sport"]=&gt;
            string(6) "soccer"
            ["id"]=&gt;
            int(244800)
          }
          [2]=&gt;
          array(2) {
            ["sport"]=&gt;
            string(6) "soccer"
            ["id"]=&gt;
            int(258740)
          }
      }
      [1]=&gt; 
          array(1) {
          [0]=&gt;
          array(2) {
            ["sport"]=&gt;
            string(10) "basketball"
            ["id"]=&gt;
            int(147884)
          }
      }
      [2]=&gt; 
      array(2) {
          [0]=&gt;
          array(2) {
            ["sport"]=&gt;
            string(8) "baseball"
            ["id"]=&gt;
            int(222240)
          }
          [1]=&gt;
          array(2) {
            ["sport"]=&gt;
            string(8) "baseball"
            ["id"]=&gt;
            int(222245)
          }
      }
  }
  </code></pre>