title: List Directories in Json File
body: <p>I can list all the images from a folder in json using the code below:</p>
  
  <pre><code>&lt;?php
  
  $dir = "images/friday/";
  $images = glob($dir."*.jpg");
  
  foreach($images as $image){
    $registro = array(
      "FILE" =&gt; $image
    );
    $retorno[] = $registro;
  }
  
  $retorno = json_encode($retorno);
  echo $retorno;
  
  ?&gt;
  </code></pre>
  
  <p>I think it would work with directories too but nothing is displayed if I don´t use print_r($dirs).</p>
  
  <pre><code>&lt;?php
  
    $path = "images";
    $dirs = glob($path . "/*", GLOB_ONLYDIR);
  
    foreach($dirs as $dir){
      $reg = array(
       "FOLDER" =&gt; $dir
       );
  
      $return[] = $reg;
    }
  
    $return = json_encode($return);
    echo $return;
  
  ?&gt;
  </code></pre>
  
  <p><strong>echo $return</strong> does not display anything. Is there a simple workaround or I have to build something like this <a href="https://stackoverflow.com/questions/15870159/list-files-on-directory-and-print-result-as-json">function</a>? I need the "FOLDER" identifier.</p>