title: Return collection or multidimensional array or array inside array in php
body: <p>This question already asked but did not find any good answer.</p>
  
  <p>To retrieve categories and subcategories in magento I am using this function:</p>
  
  <pre><code>$categories = Mage::getModel('catalog/category')
      -&gt;getCollection()
      -&gt;addAttributeToSelect('name')
      -&gt;addAttributeToSort('path', 'asc')
      -&gt;addFieldToFilter('is_active', array('eq'=&gt;'1'))
      -&gt;load()
      -&gt;toArray();
  
  // Arrange categories in required array
  $categoryList = array();
  foreach ($categories as $catId =&gt; $category) {
      if (isset($category['name'])) {
          $categoryList[] = array(
              'label' =&gt; $category['name'],
              'level'  =&gt;$category['level'],
              'value' =&gt; $catId
          );
      }
  }
  </code></pre>
  
  <p>after that if I simply use <code>return $categoryList;</code> it will not return anything(just blank) output like:</p>
  
  <pre><code>[
      [
      ],
      [
      ],
      [
      ]
  ]
  </code></pre>
  
  <p>but if  I use <code>return array(array($categoryList));</code> in that case it will give right output. </p>
  
  <p>Like this:(checking with json format)</p>
  
  <pre><code>[
      [
          [
              {
                  "label": "hello",
                  "level": "1",
                  "value": 2
              },
              {
                  "label": "hello1",
                  "level": "2",
                  "value": 10
              },
              {
                  "label": "hello3",
                  "level": "3",
                  "value": 17
              },
              {
                  "label": "Tunics",
                  "level": "3",
                  "value": 18
              }
         ]
     ]
  ]
  </code></pre>
  
  <p>but there are two more brackets and I do not want them and as I am new to php I do not have much Idea about how to remove them.</p>
  
  <p>Is there any method which can make it right or I have to create array with different style. </p>