I'm stuck with this portion where I know there is definitely a way to do this dynamically, but I just don't know how. 

How do I, upon receiving a search query, and knowing how many arrays are in the search query, dynamically creates a SQL string?

Below are parts of the code shown. Any help is appreciated, thanks! =)

```
if ($arraycount ==2){
    $searchSQL = $db->query("SELECT * FROM table WHERE field1 IN (SELECT field2 FROM $table WHERE field3 IN ('$array[0]','$array[1]'));");
}
else if ($arraycount ==3){
    $searchSQL = $db->query("SELECT * FROM table WHERE field1 IN (SELECT field2 FROM $table WHERE field3 IN ('$array[0]','$array[1]','$array[2]'));");
}

```