title: Foreach in multidimensional array doesnt work
body: <p>I have two methods for looking into directories and making a tree.</p>
  
  <pre class="lang-php prettyprint-override"><code>public function getFolders($path)
  {
      $folders = \Storage::disk('public')-&gt;directories($path);
  
      return count($folders) &gt; 0 ? $folders : [];
  }
  
  public function getTree($path = '')
  {
      if (count($tree = $this-&gt;getFolders($path)) === 0) {
          return ['nema'];
      }
  
      $arr = [];
      foreach ($tree as $value) {
          $folder = str_replace($path, '', $value);
          if (count(explode('/', $folder)) === 1) {
              if (count($this-&gt;getFolders($value)) &gt; 0) {
                  $arr[$folder] = $this-&gt;getTree($value . '/');
              } else {
                  $arr[$folder] = $folder;
              }
          }
      }
  
      return $arr;
  }
  </code></pre>
  
  <p>When I <code>dd($arr)</code> I get:</p>
  
  <pre><code>array:1 [▼
    "files" =&gt; array:2 [▼
      422 =&gt; array:1 [▶]
      "shares" =&gt; array:2 [▼
        "sasic" =&gt; array:2 [▼
          "daasdasd" =&gt; "daasdasd"
          "thumbs" =&gt; "thumbs"
        ]
        "thumbs" =&gt; "thumbs"
      ]
    ]
  ]
  </code></pre>
  
  <p>But when I try this:</p>
  
  <pre class="lang-php prettyprint-override"><code>$test = 0;
  foreach($arr as $folder) 
  {  
      if(is_array($folder)){
          $test = $test + 1;
      }
  }
  
  return $test; // returns 0 like there is zero arrays
  </code></pre>
  
  <p>The strange thing is that if I use <code>echo</code> in a <code>foreach</code>, it doesn't go from top to bottom but instead in some mixed order.</p>
  
  <p>Any ideas?</p>
  
  <p>I am trying to make the menu tree from only directories within some folder in Laravel storage public disk.</p>
  
  <p>Update: I added <code>$test</code> in the loop here by writing this part of the code. Didn't copy that so, that's not answering my question as to why the values are not in an array.</p>