title: word grouping by each word to array in PHP
body: <p>i have a bounch of array for user pemission like this:</p>
  <pre><code>[
          // home
              'home access',
                  // master data
                      'home master data access',
                          // item detail
                              'home master data item detail access',
                                  // item group
                                      'home master data item detail item group access',
                                      'home master data item detail item group create',
                                      'home master data item detail item group read',
                                      'home master data item detail item group update',
                                      'home master data item detail item group delete',
                                      'home master data item detail item group export',
                                      'home master data item detail item group import',
                                  // item name
                                      'home master data item detail item name access',
                                      'home master data item detail item name create',
                                      'home master data item detail item name read',
                                      'home master data item detail item name update',
                                      'home master data item detail item name delete',
                                      'home master data item detail item name export',
                                      'home master data item detail item name import',
                          // item category
                              'home master data item category access',
                                  // category
                                      'home master data item category category access',
                                      'home master data item category category create',
                                      'home master data item category category read',
                                      'home master data item category category update',
                                      'home master data item category category delete',
                                      'home master data item category category export',
                                      'home master data item category category import',
                          // status
                              'home master data status access',
                              'home master data status create',
                              'home master data status read',
                              'home master data status update',
                              'home master data status delete',
                              'home master data status export',
                              'home master data status import',
        // setting
              'setting access',
                  // user level
                      'setting user role access',
                      'setting user role create',
                      'setting user role read',
                      'setting user role update',
                      'setting user role delete',
                  // approval
                      'setting approval access',
                      'setting approval create',
                      'setting approval read',
                      'setting approval update',
                      'setting approval delete',
  ]
  </code></pre>
  <p>a huge amount of permission right? but that's only a small part that I copy and paste to my question.</p>
  <p>my goals is to make array result like this:</p>
  <pre><code>[
      &quot;home&quot; =&gt; [
          &quot;parent_permissions&quot; =&gt; [
              &quot;home access&quot;
          ],
          &quot;master data&quot; =&gt; [
              &quot;parent_permissions&quot; =&gt; [
                  &quot;master data access&quot;
              ],
              &quot;item detail&quot; =&gt; [
                  &quot;parent_permissions&quot; =&gt; [
                      &quot;item detail access&quot;
                  ],
                  &quot;item group&quot; =&gt; [
                      &quot;item group access&quot;,
                      &quot;item group create&quot;,
                      &quot;item group read&quot;,
                      &quot;item group update&quot;,
                      &quot;item group delete&quot;,
                      &quot;item group export&quot;,
                      &quot;item group import&quot;,
                  ],
                  &quot;item name&quot; =&gt; [
                      &quot;item name access&quot;,
                      &quot;item name create&quot;,
                      &quot;item name read&quot;,
                      &quot;item name update&quot;,
                      &quot;item name delete&quot;,
                      &quot;item name export&quot;,
                      &quot;item name import&quot;,
                  ]
              ],
              &quot;item category&quot; =&gt; [
                  &quot;parent_permissions&quot; =&gt; [
                      &quot;item category access&quot;,
                  ],
                  &quot;category&quot; =&gt; [
                      &quot;category access&quot;,
                      &quot;category create&quot;,
                      &quot;category read&quot;,
                      &quot;category update&quot;,
                      &quot;category delete&quot;,
                      &quot;category export&quot;,
                      &quot;category import&quot;,
                  ],
                  &quot;sub category&quot; =&gt; [
                      &quot;sub category access&quot;,
                      &quot;sub category create&quot;,
                      &quot;sub category read&quot;,
                      &quot;sub category update&quot;,
                      &quot;sub category delete&quot;,
                      &quot;sub category export&quot;,
                      &quot;sub category import&quot;,
                  ]
              ],
              &quot;status&quot; =&gt; [
                  &quot;status access&quot;,
                  &quot;status create&quot;,
                  &quot;status read&quot;,
                  &quot;status update&quot;,
                  &quot;status delete&quot;,
                  &quot;status export&quot;,
                  &quot;status import&quot;,
              ]
          ]
      ],
      &quot;setting&quot; =&gt; [
          &quot;parent_permissions&quot; =&gt; [
              &quot;setting access&quot;
          ],
          &quot;user role&quot; =&gt; [
              &quot;user role access&quot;,
              &quot;user role create&quot;,
              &quot;user role update&quot;,
              &quot;user role delete&quot;,
          ],
         &quot;approval&quot; =&gt; [
              &quot;approval access&quot;,
              &quot;approval create&quot;,
              &quot;approval update&quot;,
              &quot;approval delete&quot;,
         ]
      ]
  ]
  </code></pre>
  <p>i have tried <a href="https://stackoverflow.com/a/13082303/16118520">metaphone()</a> function as well, I thought that function was a way out, but not what I wanted.</p>
  <p>why did I make it like that? the answer is to make the form select permission is more readable for user and I will convert it to an html table.</p>
  <p>can you help me please?</p>
  <p><em>sorry for my bad english</em></p>