title: PHP convert nested array to single array while concatenating parent name?
body: <p>I am exporting Ebay all category and i want to store it in my database so i would display it in dropdown later.</p>
  
  <p>Here is an example array:</p>
  
  <pre><code>$foo = array(
      0 =&gt; array(
          ['category'] =&gt; array(
              ['categoryId'] =&gt; 1,
              ['categoryName'] =&gt; 'Collectables'
          ),
          ['child'] =&gt; array(
              0 =&gt; array(
                  ['category'] =&gt; array(
                      ['category'] =&gt; array(
                          ['categoryId'] =&gt; 34,
                          ['categoryName'] =&gt; 'Advertising'
                      ),
                      ['child'] =&gt; array(
                          0 =&gt; array(
                              ['category'] =&gt; array(
                                  ['categoryId'] =&gt; 35,
                                  ['categoryName'] =&gt; 'Other Advertising'
                              ),
                          ),
                          1 =&gt; array(
                              ['category'] =&gt; array(
                                  ['categoryId'] =&gt; 36,
                                  ['categoryName'] =&gt; 'Drinks'
                              ),
                              ['child'] =&gt; array(
                                  0 =&gt; array(
                                      ['category'] =&gt; array(
                                          ['categoryId'] =&gt; 13601,
                                          ['categoryName'] =&gt; 'Coca Cola'
                                      ),
                                  )
                              )
                          )
                      )
                  )
              ),
          )
      ),
      1 =&gt; array(
          ['category'] =&gt; array(
              ['categoryId'] =&gt; 99,
              ['categoryName'] =&gt; 'Everything Else'
          ),
          ['child'] =&gt; array(
              0 =&gt; array(
                  ['category'] =&gt; array(
                      ['categoryId'] =&gt; 3133,
                      ['categoryName'] =&gt; 'Educational'
                  ),
              ),
              1 =&gt; array(
                  ['category'] =&gt; array(
                      ['categoryId'] =&gt; 14112,
                      ['categoryName'] =&gt; 'Test Auctions'
                  ),
                  ['child'] =&gt; array(
                      0 =&gt; array(
                          ['category'] =&gt; array(
                              ['categoryId'] =&gt; 37558,
                              ['categoryName'] =&gt; 'Attributes1'
                          ),
                      ),
                      1 =&gt; array(
                          ['category'] =&gt; array(
                              ['categoryId'] =&gt; 37561,
                              ['categoryName'] =&gt; 'Attributes4'
                          ),
                      ),
                  )
              )
          )
      )
  );
  </code></pre>
  
  <p>And I would like to get a result like this:</p>
  
  <pre><code>$result = array(
      0 =&gt; array(
          ['categoryId'] =&gt; 1,
          ['categoryName'] =&gt; 'Collectables'
      ),
      1 =&gt; array(
          ['categoryId'] =&gt; 34,
          ['categoryName'] =&gt; 'Collectables =&gt; Advertising'
      ),
      2 =&gt; array(
          ['categoryName'] =&gt; 35,
          ['categoryId'] =&gt; "Collectables =&gt; Advertising =&gt; Other Advertising",
      ),
      3 =&gt; array(
          ['categoryName'] =&gt; 36,
          ['categoryId'] =&gt; "Collectables =&gt; Advertising =&gt; Drinks ",
      ),
      4 =&gt; array(
          ['categoryName'] =&gt; 13601,
          ['categoryId'] =&gt; "Collectables =&gt; Advertising =&gt; Drinks =&gt; Coca Cola",
      ),
      5 =&gt; array(
          ['categoryName'] =&gt; 99,
          ['categoryId'] =&gt; "Everything Else",
      ),
      6 =&gt; array(
          ['categoryName'] =&gt; 3133,
          ['categoryId'] =&gt; "Everything Else =&gt; Educational",
      ),
  );
  </code></pre>
  
  <p>and so on till all the child of array.
  How would I go about writing a recursive function of PHP array to handle this?
  Any help greatly appreciated.</p>