Build it into your function. Just pass the filetype to it.
Something like this
function GetDirArray($sPath, $filetype){
global $file_array;
$length = "-".strlen($filetype);
$handle=opendir($sPath);
$i=0;
while (false!==($file = readdir($handle))) {
if($file != "." && $file != "..") {
if(substr($file,$length) == $filetype) {
$file_array[]= $file;
$i++;
}
}
}
Though, I need to comment on your function. It needs work. You have an incrementing variable for seemingly no reason, and you never return anything. With what you're doing, there seems to be no reason to have it as a function. Of course, I could be wrong, but just thought I'd give my 2 cents