Question: ```
        $za = new ZipArchive();
        $za->open($source);
        for( $i = 0; $i < $za->numFiles; $i++ ){
            $stat = $za->statIndex( $i );
            $items = array( basename( $stat['name'] ) . PHP_EOL );
            foreach($items as $item) {
            echo $item;
            }
        }

```

This code will list all files inside a zip archive but i want to exclude folders listing. If the item in the array is a folder, i want to exclude it from the array BUT i still want to list the files inside the folder. Just don't display the folder's name in the list.

Is there a way i can detect if the item is a directory in my foreach loop (how?) or do i need to run a search on the array and look for folders then unset it (how?) ?

Thanks for your help

Answer: 
Your foreach is useless. It iteratate over array with one item.

Anyway there is two way to detect folder. First, folders are ended with '/'. Second folders has 0 size.

```
$za = new ZipArchive();
$za->open('zip.zip');
$result_stats = array();
for ($i = 0; $i < $za->numFiles; $i++)
    {
    $stat = $za->statIndex($i);
    if ($stat['size'])
        $result_stats[] = $stat;
    }

echo count($result_stats);

```
If you are looking for a simple PHP function to list files and folders but not sub-folders, here is a simple crafted function that you may test and see if it would work for you.

```
function unzip($path){

  if($path ===  null ) return 'File not found.';
    $zip = new ZipArchive();

   $entryList  = '<ul class="list-group"> ';

   if ($zip->open($path) == TRUE) {
      for ($i = 0; $i < $zip->numFiles; $i++) {

       //set the prerequisit inputs
       $stat =  $zip->statIndex($i); //an array of file statistics or details
       $filename =  $stat['name']; // entry name
       $size =  $stat['size']; //entry size

       //list only folders and file names but not subfolders.
       //when size is zero,its folder, list it, and when entry name
       //doesn't contain the (/), its is a file, list it.

      $isFile  =  strstr($filename, '/') === false;
      $anyFile  = preg_match('/(\..+)$/',$filename);
      $icon = ($anyFile  ? 'fa-file text-info' : 'fa-folder text-warning' );

      if($size == 0 || $isFile  ){
          $filename = str_replace('/','',$filename);
          $entryList .='<li class="list-group-item  ">';
          $entryList .=  '<i class="fa '.$icon.' mr-1 "></i>';
          $entryList .='<button class="btn btn-link">'.$filename.'</button></li>';
    }
 }

   $zip->close();
  }

  return $entryList.'</ul>' ;

 }

```

and here is the output:
[![File list](https://i.stack.imgur.com/ZuDdC.png)](https://i.stack.imgur.com/ZuDdC.png)