Another solution, once you have a folder path... this will count the number of folders immediately within that folder (non-recursive):
PHP Code:
$sub_directories = glob( realpath( $directory ) . '/*', GLOB_ONLYDIR );
$sub_directories_count = count( $sub_directories );