title: How to group elements of array using Primary and secondary key?
body: <p>I've got this array:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [id]=&gt;1
              [account_id] =&gt; 1
              [object_id] =&gt; 43
              [object_type] =&gt; PHOTO
              [action_type] =&gt; UPLOAD_PHOTO
          )
  
      [1] =&gt; Array
          (
              [id] =&gt; 1
              [account_id] =&gt; 1
              [object_id] =&gt; 42
              [object_type] =&gt; PHOTO
              [action_type] =&gt; UPLOAD_PHOTO
          )
  
      [2] =&gt; Array
          (
              [id] =&gt; 1
              [account_id] =&gt; 1
              [object_id] =&gt; 41
              [object_type] =&gt; PHOTO
              [action_type] =&gt; UPLOAD_PHOTO
          )
  
      [3] =&gt; Array
          (
              [id] =&gt; 2
              [account_id] =&gt; 2
              [object_id] =&gt; 1
              [object_type] =&gt; USER
              [action_type] =&gt; FOLLOW_USER
          )
  
      [4] =&gt; Array
          (
              [id] =&gt; 1
              [account_id] =&gt; 1
              [object_id] =&gt; 2
              [object_type] =&gt; USER
              [action_type] =&gt; FOLLOW_USER
          )
  
      [5] =&gt; Array
          (
              [id] =&gt; 1
              [account_id] =&gt; 1
              [object_id] =&gt; 1
              [object_type] =&gt; PHOTO
              [action_type] =&gt; UPLOAD_PHOTO
          )
  
  )
  </code></pre>
  
  <p>Now I want to group elements have same value (for example <code>UPLOAD_PHOTO</code>) by <strong>id</strong> as Primary Key and <strong>action_type</strong> as Secondary Key, like:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array(
          [id] =&gt; 1
          [account_id] =&gt; 1
          [actions] =&gt; array(
            [1] =&gt; array(
                [object_id] =&gt; 42
                [object_type] =&gt; PHOTO
                [action_type] =&gt; UPLOAD_PHOTO
             )
            [2] =&gt; array(
                [object_id] =&gt; 43
                [object_type] =&gt; PHOTO
                [action_type] =&gt; UPLOAD_PHOTO
             )
           )      
  
   ) 
  [2] =&gt; Array
      (
          [id] =&gt; 1
          [account_id] =&gt; 1
          [actions] = array(
              [0] =&gt; Array
               (
                 [object_id] =&gt; 3
                 [object_type] =&gt; USER
                 [action_type] =&gt; FOLLOW_USER
               )
              [1] =&gt; Array
               (
                 [object_id] =&gt; 4
                 [object_type] =&gt; USER
                 [action_type] =&gt; FOLLOW_USER
               )
  
          )
  
      )
  
  )
  </code></pre>
  
  <p>I tried some solutions but didn't succeed.</p>