title: can not convert multidimensional array to single php array
body: <p>I am trying to convert a multidimensional php array to a single array.. but having difficulty to do that. My given input is like:</p>
  <pre><code>array ( 0 =&gt; array ('id' =&gt; 3,
  'text' =&gt; 'Name 3',
  'children' =&gt; 
  array (
    0 =&gt; 
    array (
      'id' =&gt; 4,
      'text' =&gt; 'Name 4',
      'children' =&gt; 
      array (
        0 =&gt; 
        array (
          'id' =&gt; 5,
          'text' =&gt; 'Name 5',
          'children' =&gt; 
          array (
            0 =&gt; 
            array (
              'id' =&gt; 6,
              'text' =&gt; 'Name 6',
            ),
          ),
        ),
      ),
    ),
    1 =&gt; 
    array (
      'id' =&gt; 7,
      'text' =&gt; 'name 7',
    ),
  ),),)
  </code></pre>
  <p>and my expected output is like this:</p>
  <pre><code>array(3=&gt;'Name 3', 4=&gt;'name 4', 5=&gt;'name 5', 6=&gt;'name 6', 7=&gt;'name 7')
  </code></pre>
  <p>I've tried so far as follows:</p>
  <pre><code>function nestedToSingle($array)
  {
      $singleDimArray = [];
  
      foreach ($array as $item) {
  
          if (is_array($item)) {
  
              $singleDimArray = array_merge($singleDimArray, nestedToSingle($item));
          } else {
              $singleDimArray[] = $item;
          }
      }
  
      return $singleDimArray;
  }
  </code></pre>
  <p>but it giving me output like this:</p>
  <pre><code>array ( 0 =&gt; 3, 1 =&gt; 'name 3',  2 =&gt; 4,  3 =&gt; 'Name 4',  4 =&gt; 5,  5 =&gt; 'name 5',  6 =&gt; 6,  7 =&gt; 'name 6',  8 =&gt; 7,  9 =&gt; 'name 7',)
  </code></pre>