title: Group slice by subarray values in Go
body: <p>I have an array of subarrays in the following format</p>
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [unit_id] =&gt; 6504
              [assignment_name] =&gt; Grade assignment 
              [assignment_description] =&gt; 
              [assignment_total_score] =&gt; 10
              [unit_type_name] =&gt; Homework
              [is_graded] =&gt; 1
              [standard_id] =&gt; 1219
              [scoring_type] =&gt; score
              [attempt_score] =&gt; 8
              [unit_duedate] =&gt; 2016-02-10 09:00:00
              [standard] =&gt; Array
                  (
             
                      [0] =&gt; stdClass Object
                          (
                              [unit_id] =&gt; 6504
                              [is_formal] =&gt; 1
                              [assignment_name] =&gt; Grade assignment 
                              [assignment_description] =&gt; 
                              [standard_id] =&gt; 1220
                              [standard_name] =&gt; 9-10.RL.3
                              [standard_description] =&gt; Analyze how complex characters (e.g., those with multiple or conflicting motivations) develop over the course of a 
                          )
  
                  )
  
          )
  
      [1] =&gt; Array
          (
              [unit_id] =&gt; 8584
              [assignment_name] =&gt; Sine and Cosecant Graphs
              [assignment_description] =&gt; Define the sine and cosecant graphs using a unit circle
              [assignment_total_score] =&gt; 15
              [unit_type_name] =&gt; Paper
              [scoring_type] =&gt; score
              [attempt_score] =&gt; 0
              [unit_duedate] =&gt; 2016-04-29 09:00:00
              [standard] =&gt; Array
                  (
  
                      [0] =&gt; stdClass Object
                          (
                              [unit_id] =&gt; 8584
                              [is_formal] =&gt; 1
                              [assignment_name] =&gt; Sine and Cosecant Graphs
                              [assignment_description] =&gt; Define the sine and cosecant graphs using a unit circle
                              [assignment_total_score] =&gt; 15
                              [standard_id] =&gt; 82790
                              [standard_name] =&gt; 9-10.RL.7
        
  
                  )
  
          )
  
      [2] =&gt; Array
          (
              [unit_id] =&gt; 11611
              [assignment_name] =&gt; Adding 5 + 3 + 6
              [assignment_description] =&gt; 
              [assignment_total_score] =&gt; 10
              [unit_type_name] =&gt; Homework
              [standard_id] =&gt; 82772
              [scoring_type] =&gt; score
              [attempt_score] =&gt; 0
              [unit_duedate] =&gt; 2016-08-23 19:00:00
              [standard] =&gt; Array
                  (
                      [0] =&gt; stdClass Object
                          (
                              [unit_id] =&gt; 11611
                              [is_formal] =&gt; 1
                              [assignment_name] =&gt; Adding 5 + 3 + 6
                              [assignment_description] =&gt; 
                              [assignment_total_score] =&gt; 10
                              [standard_id] =&gt; 82772
                              [standard_name] =&gt; 9-10.RL.1
  
                          )
  
                  )
  
          )
  
  )
  </code></pre>
  <p>And I would like to group it into a new slice based on the <code>unit_type_name</code> field in each subarray.</p>
  <p>How can I group the slice by <code>unit_type_name</code>? Is there any native Go functions are available to do this?
  if I for loop the above then I will get a duplicate one, how can I avoid that?</p>