$path = "folder/path/"; $dir = scandir($path); foreach($dir as $file) { echo $file . "
"; }
$path = "folder/path/"; $dir = scandir($path); $files = array(); foreach($dir as $file) { if ($file != "." && $file != "..") { if (is_dir($path.$file)) { $files[$file] = scandir($path.$file); } else { $files[] = $file; } } } print_r($files);In this example, `scandir()` is used to get the list of all files and directories located within the folder path `$path`. However, this time the `if` statement filters out the current and parent directory (`.` and `..`) on each iteration. If the current file is a directory, its contents are added to the `$files` array as a nested array. If it's a regular file, it's added to the `$files` array as a string. Finally, `print_r()` is used to print the contents of the `$files` array. These examples use PHP's built-in functions and do not require any external package libraries.