title: Array of file objects to tree structure
body: <pre><code>Array
  (
      [dir1/dir1-1/] =&gt; Array
          (
              [name] =&gt; name1.pdf
              [size] =&gt; 816701
              [type] =&gt; pdf
              [date] =&gt; 2020-08-27 18:49:24
          )
  
      [dir1/dir1-1/] =&gt; Array
          (
              [name] =&gt; name2.pdf
              [size] =&gt; 394459
              [type] =&gt; pdf
              [date] =&gt; 2020-08-17 18:13:43
          )
  
      [dir1/dir1-2/] =&gt; Array
          (
              [name] =&gt; name3.pdf
              [size] =&gt; 1536144
              [type] =&gt; pdf
              [date] =&gt; 2020-11-11 12:53:34
          )
  
      [dir1/dir1-2/dir1-2-1/] =&gt; Array
          (
              [name] =&gt; name4.pdf
              [size] =&gt; 10047255
              [type] =&gt; pdf
              [date] =&gt; 2021-11-18 12:34:43
          )
      [dir2/dir2-1/] =&gt; Array
          (
              [name] =&gt; name5.pdf
              [size] =&gt; 13419981
              [type] =&gt; pdf
              [date] =&gt; 2022-03-11 15:13:24
          )
  </code></pre>
  <p>Using PHP, I would like to turn a flattened list of file objects, with keys defining their directory structure, into a JSON tree that can used by this finder library:</p>
  <p><a href="https://github.com/bu/hColumns" rel="nofollow noreferrer">https://github.com/bu/hColumns</a></p>
  <pre><code>let data = [
        {
          content: [
            {
              label: &quot;dir1&quot;, 
              type: &quot;folder&quot;,
              content: [
                {
                  label: &quot;dir1-1&quot;,
                  type: &quot;folder&quot;,
                  content: [
                    {
                      label: &quot;name1.pdf&quot;,
                      size: 816701,
                      type: &quot;file&quot;,
                      date: 2020-08-27 18:49:24
  
                    },
                    {
                      label: &quot;name2.pdf&quot;,
                      size: 394459,
                      type: &quot;file&quot;,
                      date: 2020-08-17 18:13:43
                    }
                  ]
                },
                {
                  label: &quot;dir1-2&quot;,
                  type: &quot;folder&quot;,
                  content: [
                    {
                      label: &quot;name3.pdf&quot;,
                      size: 1536144,
                      type: &quot;file&quot;,
                      date: 2020-11-11 12:53:34
  
                    },
                    {
                      label: &quot;dir1-2-1&quot;,
                      type: &quot;folder&quot;,
                      content: [
                        {
                          label: &quot;name4.pdf&quot;,
                          size: 10047255,
                          type: &quot;file&quot;,
                          date: 2021-11-18 12:34:43
                        }
                      ]
                    }
                  ]
                }
              ]
  </code></pre>
  <p>The example uses directory names that somewhat explain the hierarchy, but in my actual use, they'll be somewhat arbitrary.</p>
  <p><a href="https://stackoverflow.com/questions/23889469/creating-filetree-from-full-path-in-php">Creating filetree from full path in php</a></p>
  <p>I started with the solution provided in this post, but it doesn't use file objects, but rather just string endpoints. Has anyone yet modified the solution yet to work in the objects?</p>