How can an array be structured in PHP to store subfolders as a one-dimensional array for easy access and manipulation?

When dealing with subfolders in PHP, you can structure an array to store them as a one-dimensional array by using a recursive function to iterate through the directory structure and store the paths in the array. This allows for easy access and manipulation of the subfolders.

function getSubfolders($dir) {
    $subfolders = [];
    $files = scandir($dir);
    
    foreach($files as $file) {
        if ($file != '.' && $file != '..' && is_dir($dir . '/' . $file)) {
            $subfolders[] = $dir . '/' . $file;
            $subfolders = array_merge($subfolders, getSubfolders($dir . '/' . $file));
        }
    }
    
    return $subfolders;
}

$directory = 'path/to/your/directory';
$subfoldersArray = getSubfolders($directory);

// Now $subfoldersArray contains all the subfolders in a one-dimensional array for easy access and manipulation