title: Create path to each array item
body: <p>I've built a recursive PHP function to create a multidimensional array with parents/children. Now I want to create a function to create a list with paths to each array item. See the following array:</p>
  
  <pre><code>$testdata = [
      ['id' =&gt; 1, 'parent_id' =&gt; null, 'desc' =&gt; 'Vehicles'],
      ['id' =&gt; 2, 'parent_id' =&gt; 1, 'desc' =&gt; 'Cars'],
      ['id' =&gt; 3, 'parent_id' =&gt; 1, 'desc' =&gt; 'Motorbikes'],
      ['id' =&gt; 4, 'parent_id' =&gt; 1, 'desc' =&gt; 'Planes'],
      ['id' =&gt; 5, 'parent_id' =&gt; 2, 'desc' =&gt; 'Toyota'],
      ['id' =&gt; 6, 'parent_id' =&gt; 2, 'desc' =&gt; 'Volkswagen'],
      ['id' =&gt; 7, 'parent_id' =&gt; 2, 'desc' =&gt; 'Renault'],
      ['id' =&gt; 8, 'parent_id' =&gt; 3, 'desc' =&gt; 'Honda'],
      ['id' =&gt; 9, 'parent_id' =&gt; 3, 'desc' =&gt; 'Yamaha'],
      ['id' =&gt; 10, 'parent_id' =&gt; 4, 'desc' =&gt; 'Boeing'],
      ['id' =&gt; 11, 'parent_id' =&gt; null, 'desc' =&gt; 'Cities'],
      ['id' =&gt; 12, 'parent_id' =&gt; 11, 'desc' =&gt; 'Amsterdam'],
      ['id' =&gt; 13, 'parent_id' =&gt; 11, 'desc' =&gt; 'New York'],
  ];
  </code></pre>
  
  <p>Now the expected result should be like this:</p>
  
  <pre><code>$output = [
      'Vehicles'
      'Vehicles\Cars'
      'Vehicles\Cars\Toyota'
      'Vehicles\Cars\Volkswagen'
      'Vehicles\Cars\Renault'
      'Vehicles\Motorbikes'
      'Vehicles\Motorbikes\Honda'
      'Vehicles\Motorbikes\Yamaha'
      'Vehicles\Planes'
      'Vehicles\Planes\Boeing'
      'Cities'
      'Cities\Amsterdam'
      'Cities\New York'
  ];
  </code></pre>
  
  <p>I have tried to rebuild my recursive function, but I can't wrap my head around it. Could you guys give me some advice or a push me in the right direction?</p>