A new function for flattening an array