Type cast as an array in foreach, fixes #82

@kucrut Please review

/cc @shadyvb