title: PHP implode array to generate mysql IN criteria
body: <p>I have a function like the following:</p>
  
  <pre><code>public function foo ($cities = array('anaheim', 'baker', 'colfax') )
  {
      $db = global instance of Zend_Db_Adapter_Pdo_Mysql...
  
      $query = 'SELECT name FROM user WHERE city IN ('.implode(',',$cities).')';
      $result = $db-&gt;fetchAll( $query );
  }
  </code></pre>
  
  <p>This works out fine until someone passes $cities as an empty array.</p>
  
  <p>To prevent this error I have been logic-breaking the query like so:</p>
  
  <pre><code>$query = 'SELECT name FROM user';
  if (!empty($cities))
  {
      $query .= ' WHERE city IN ('.implode(',',$cities).')';
  }
  </code></pre>
  
  <p>but this isn't very elegant.  I feel like there should be a better way to filter by a list, but I am not sure how.  Any advice?</p>