title: Count specific condition within an if statement
body: <p>In a PHP script, I perform a specific task in batches of <code>ITERATIONS_PER_LOOP</code>. Within the foreach loop that performs the task, I have an if statement with some conditions. The thing is I want to count the times 2 of those conditions (all of them are 3) are met. But I can't seem to find a (elegant) way to do that. Please take a look at the code below.</p>
  <p>So my original was this:</p>
  <pre><code>    if (in_array($publication, $blacklist) || !remote_file_exists($remote['frontpage']['url']) || $iterations &gt;= ITERATIONS_PER_LOOP) {
          continue;
      }
  </code></pre>
  <p>which I changed to the following:</p>
  <pre><code>    if ($skip = (in_array($publication, $blacklist) || !remote_file_exists($remote['frontpage']['url'])) || $iterations &gt;= ITERATIONS_PER_LOOP) {
          if ($skip) {
              $skipped++;
          }
  
          continue;
      }
  </code></pre>
  <p>The idea was to assign the condition of the first two statements being met to a var, then count the times that var - <code>$skip</code> - was assigned a true value. However this doesn't seem to work as expected, as it counts not only the occurrences of a non-existent file or a blacklisted file, but also the remaining iterations that will occur in next loops.</p>
  <p>So, let's say we have a batch of 100 items to process and the <code>ITERATIONS_PER_LOOP</code> is set to 10.</p>
  <p>Let's also say that in the first 2 batches we didn't sequentially meet a blacklisted item, nor an item without a valid image. Then the $skipped counter should be 0.</p>
  <p>In the 3rd batch let's assume we hit 1 blacklisted item and 2 items with missing images. In this batch the counter <strong>should</strong> be 3.</p>
  <p>Ah, I forgot to mention that at each iteration, the batch starts from the beginning, and already done items are taken care at another part of the script.</p>
  <p>So, in the 4th batch, we found 1 more blacklisted item, and 6 items with a missing image. Now the counter <strong>should</strong> read 10 (3 from the previous batch plus 7 from this one).</p>
  <p>Etc etc...</p>
  <p>Instead, the code above for the first run says skipped 90 (remember the <code>ITERATIONS_PER_LOOP</code> is set to 10). In the 2nd batch it shows 80.</p>
  <p>In the 3rd batch it'd show 67 (it would show 70 but subtracts the 3 really skipped ones from it, so it shows 67)...</p>
  <p>What am I doing wrong here?</p>