title: Array is empty after loop in PHP
body: <p>I am trying to make an <code>ARRAY</code> of files and subfolder inside a specific folder. I got success in getting a list of files and subfolders but when I try kept this data in an <code>ARRAY</code> it only show result as expected within <code>LOOP</code>. Once <code>LOOP</code> finished it <code>return EMPTY</code></p>
  
  <p>Here is full code</p>
  
  <pre><code>&lt;?php
  function dirToOptions($path = '../data/vid/', $level = 0) {
      $items = scandir($path);
      $vidCount = 0; $thumbCount = 0;
      foreach($items as $item) {
          // ignore items strating with a dot (= hidden or nav)
          if (strpos($item, '.') === 0) {
              continue;
          }
  
          $fullPath = $path . DIRECTORY_SEPARATOR . $item;
          // add some whitespace to better mimic the file structure
          $item = str_repeat('&amp;nbsp;', $level * 3) . $item;
          // file
          if (is_file($fullPath)) {
              $rrInt = (int)$level-1;
              if($rrInt == 0){
                  $vid['videos'][] = array('name'=&gt;$item, 'link'=&gt;$fullPath);
                  echo "&lt;a href='$fullPath'&gt;&lt;i for='$rrInt'&gt;$item&lt;/i&gt;&lt;/a&gt;&lt;br /&gt;";
              }elseif($rrInt == 1){
                  $thumb['thumbs'][] = array('name'=&gt;$item, 'link'=&gt;$fullPath);
                  echo "&lt;a href='$fullPath'&gt;&lt;i for='$rrInt'&gt;$item&lt;/i&gt;&lt;/a&gt;&lt;br /&gt;";
                  var_dump($thumb); //SHOW RESULT HERE
              }
          }
          // dir
          else if (is_dir($fullPath)) {
              // immediatly close the optgroup to prevent (invalid) nested optgroups
              echo "&lt;b label='$level'&gt;$item&lt;/b&gt;&lt;br /&gt;";
              // recursive call to self to add the subitems
              dirToOptions($fullPath, $level + 1);
          }
      }
  }
  
  $array = array(); $vid = array(); $thumb = array();
  
  echo '&lt;div&gt;';
  dirToOptions();
  echo '&lt;/div&gt;';
  
  var_dump($vid); // RETURN EMPTY
  ?&gt;
  </code></pre>
  
  <blockquote>
    <p>Thanks to all for support but at last I prefer to use <code>GLOBAL VARS</code></p>
  </blockquote>