title: Reshape multidimensional nested PHP array to another format
body: <p>I have a multidimensional nested array:</p>
  
  <pre><code>$arr = array(
      'name'      =&gt; 'Root Node',
      'children'  =&gt; array(
          array(
              'name'      =&gt; 'Node A',
              'children'  =&gt; array(
                  array(
                      'name'      =&gt; 'Node A.1',
                      'children'  =&gt; array(
                          array(
                              'name'      =&gt; 'Node A.1.1',
                              'children'  =&gt; ''
                          ),
                      ),
                  ),
  
                  array(
                      'name'      =&gt; 'Node A.2',
                      'children'  =&gt; ''
                  ),
              ),
          ),
  
          array(
              'name'      =&gt; 'Node B',
              'children'  =&gt; array(
                  array(
                      'name'      =&gt; 'Node B.1',
                      'children'  =&gt; '',
                  ),
  
                  array(
                      'name'      =&gt; 'Node B.2',
                      'children'  =&gt; ''
                  ),
              )
          ),
  
          array(
              'name'      =&gt; 'Node C',
              'children'  =&gt; ''
          )
      ),
  );
  </code></pre>
  
  <p>Currently this array is upto 4 levels but we can't assume its depth level static to 4 as it may have N levels as well. My goal is to convert this array with individual row array per relation like:</p>
  
  <pre><code>$arr = array(
      array( 'Root Node', 'Nodel A', 'Node A.1', 'Node A.1.1' ),
      array( 'Root Node', 'Nodel A', 'Node A.2' ),
      array( 'Root Node', 'Nodel B', 'Node B.1' ),
      array( 'Root Node', 'Nodel B', 'Node B.2' ),
      array( 'Root Node', 'Nodel C' ),
  );
  </code></pre>
  
  <p>I know a recursive function should do the trick but I can't figure it out as its not that easy I thought in start. Any help would be greatly appreciated!</p>