Checking if a folder is empty or not using PHP

Hi,
I am sharing this tip with you all.The codes given below will explain

/**
 * Checking a folder is empty or not.
 * @param string $folderName
 * $folderName should be folder name or path
 * @return TRUE/FALSE (If any file or folder found/Empty folder)
 */
 
function checkFolderIsEmptyOrNot ( $folderName ){
    $files = array ();
    if ( $handle = opendir ( $folderName ) ) {
        while ( false !== ( $file = readdir ( $handle ) ) ) {
            if ( $file != "." && $file != ".." ) {
                $files [] = $file;
            }
        }
        closedir ( $handle );
    }
    return ( count ( $files ) > 0 ) ?  TRUE: FALSE;
}

From the php.net website:

<?php
public static function isEmptyDir($dir){
     return (($files = @scandir($dir)) && count($files) <= 2);
}
?>