Reputation: 8280
I am wondering how i can find all rows that have the same ID as one of the values in an array.. so lets say:
Array(1,2,5,6,99,467);
Now i want to query all rows which have an id in that array, my initial idea was to loop the array and use a SELECT on each field, but i am wondering if i can skip that process with some kind of in_array method to make a bit more efficient?
Upvotes: 0
Views: 58
Reputation: 254926
SELECT *
FROM table
WHERE id IN (' . implode(', ', $arr) . ')
PS: if the data comes from outside and can contain non-numbers - it could worth performing array_map('intval', $arr)
before
Upvotes: 4