Cast msgstr to Array before foreach if msgstr is a string