in_array() is the correct function to use:
$ext = preg_replace("/.*./", "", $imagefile_name);
if(in_array($ext, $formats)){
echo "File type is ok";
}else{
echo "File type not ok";
in_array basically does a foreach() on your array and returns true if $arrayitem == $yourvalue
I think your regular expression might be a bit suspect
$ext = preg_replace("/.*?\\.(.*?)/si", "$1", $imagefile_name);
maybe better. Or use a PHP built-in function.