title: Using Logical AND Operators && in foreach php
body: <p>I have the following code for an image gallery : </p>
  
  <pre><code>$directory = 'some path';
  $thumbs_directory = 'some path';
  foreach (glob($directory.'/*.{jpg,jpeg,png,gif}', GLOB_BRACE) as $file) 
  foreach (glob($thumbs_directory.'/*.{jpg,jpeg,png,gif}', GLOB_BRACE) as $file2)
  {
  
      if($file=='.' || $file == '..') continue;
      $file_parts = explode('.',$file);
      $ext = strtolower(array_pop($file_parts));
      $title = basename($file);
      $title = htmlspecialchars($title);
      $title = str_replace("_"," ",$title);
      $nomargin='';
      if(($i+1)%4==0) $nomargin='nomargin';
      echo '
      &lt;div class="pic '.$nomargin.'" style="background:url('.$file2.') no-repeat 50% 50%;"&gt;
      &lt;a href="'.$file.'" title="'.$title.'" target="_blank"&gt;'.$title.'&lt;/a&gt;
      &lt;/div&gt;';
      $i++;
  }
  </code></pre>
  
  <p>I need to combine these foreach statements through the Logical AND operator &amp;&amp; so that both conditions are satisfied at the same time. Is it possible ? I've tried numerous times, but always ends up in a Syntax error.</p>
  
  <p>Please note that I need $file and $file2 variables defined perfectly. That is only the way for the thumbnails to associate with the images properly.</p>