How to use php array with sql IN operator? [duplicate]

Since you have plain integers, you can simply join them with commas: $sql = “SELECT * FROM table WHERE comp_id IN (” . implode(‘,’, $arr) . “)”; If working with with strings, particularly untrusted input: $sql = “SELECT * FROM table WHERE comp_id IN (‘” . implode(“‘,'”, array_map(‘mysql_real_escape_string’, $arr)) . “‘)”; Note this does not … Read more