Sounds like a database design problem. Those numbers you have in an array should be in another table. Then with one query, you could fetch all your categories.
MySQL has some string handling functions, but I'm pretty sure it doesn't have explode available to it.
You could do what you were thinking which is pull the array out and then process it with PHP and then requery.
You might be able to just use the array in the WHERE clause as "WHERE categoryID IN (1,2,3,4,5)". But I don't have enough info to know if this would help or not...