title: How to concatenate string with OR-operator in php?
body: <p>I want to build a query based on the output from a for-loop. The query now looks like this:</p>
  
  <pre><code>$result = $pdo-&gt;query("SELECT {$fields}, ST_AsGeoJSON(geom, 5) AS geojson FROM government_table WHERE '".$gov_where_statement."' {$order}");
  </code></pre>
  
  <p>and the <code>$gov_where_statement</code> comes from the for-loop:</p>
  
  <pre><code>for ($i=0; $i&lt;count($gov)-1; $i++){
      $gov_where_statement .="government='".$gov[$i]."' "&amp;&amp;" ";
  }
  
  for ($i=0; $i&lt;count($gov); $i++){
    if( !next( $gov ) ) {
        $gov_where_statement .="government='".$gov[$i]."'"; 
     }
  }
  </code></pre>
  
  <p>If there are three governments, I want the query to be interpreted as:</p>
  
  <pre><code> $result = $pdo-&gt;query("SELECT {$fields}, ST_AsGeoJSON(geom, 5) AS geojson FROM government_table WHERE government='first' &amp;&amp; government='second' &amp;&amp; government='third' {$order}");
  </code></pre>
  
  <p>Problem arises in first part of the for-loop with the "&amp;&amp;". Putting a var_dump($gov_where_statement) after the for-loop returns 11government='third' where 11 comes from the for-loop with the &amp;&amp;-operator. If there would have been four governments it would look like: 111government='fourth'.</p>
  
  <p>How can I produce <code>government='first' &amp;&amp; government='second' &amp;&amp; government='third'</code> so that the query understand the &amp;&amp;-operator?</p>