Parsing Directories

/**
 * Converts a nested directory tree into a multidimensional array
 * structured to represent the nesting hierarchy of all
 * files and directories defined by '$startpath'.
 */
function get_recursive_dir_file_listings( $startpath )
{
    $listings_array = array();

    $raw_listings = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator( $startpath ),
        RecursiveIteratorIterator::CHILD_FIRST
    );

    foreach ($raw_listings as $splFileInfo)
    {
        if( $splFileInfo->isDir() )
        {
            $path = array( $splFileInfo->getFilename() => array() );
        }
        else
        {
            $path = array( $splFileInfo->getFilename() ); 
        }

        for( $depth = $raw_listings->getDepth() - 1; $depth >= 0; $depth-- )
        {
           $path = array( $raw_listings->getSubIterator( $depth )->current()->getFilename() => $path ); 
        } 

        $listings_array = array_merge_recursive( $listings_array, $path ); 
    } 

    return $listings_array;
}

// Example:
// This will print an array containing the contents of
// the current directory and everything under it.

print_r( get_recursive_dir_file_listings( __DIR__ ) ) ;