The error is because your logic is imploding/joining the array into a string, so there’s nothing to foreach(){} over. The print_r() only LOOKS correct, because it contains the value(s) you expect to see. You are also putting that string directly into the sql query statement, rather than the necessary place-holders (using an IN() statement requires a place-holder for each value.)
An alternative to using IN(), is to use FIND_IN_SET(), which will take a single place-holder and an imploded comma separated value.
Edit: which I see you were already told in a reply in another thread for this same problem - How to select results when variable is an array - #3 by mabismad