There are other several code style issues but for example this line doesn't accomplish it. It should be:

if (in_array(end($explodeArray), $extensions))