title: What is quickest? Conditions inside a loop or outside?
body: <p>What is quickest? To do a condition <em>based on a variable outside the loop</em> inside a loop or outside, or does it even matter (does the compiler do it for you), or should you maybe use a completely different workaround?</p>
  
  <p><strong>Example #1 with the condition inside the loop (a single foreach):</strong></p>
  
  <pre><code>$test = 2;  
  foreach ($list as $listItem) {
      if ($test == 1) {
          $listItem .= " - one";
      } else if ($test == 2) {
          $listItem .= " - two";
      } else if ($test == 3) {
          $listItem .= " - three";
      }
  }
  </code></pre>
  
  <p><strong>Example #2 with the condition outside the loop (quite ugly with multiple foreach's):</strong></p>
  
  <pre><code>$test = 2;  
  if ($test == 1) {
      foreach ($list as $listItem) {
          $listItem .= " - one";
      }
  } else if ($test == 2) {
      foreach ($list as $listItem) {
          $listItem .= " - two";
      }
  } else if ($test == 3) {
      foreach ($list as $listItem) {
          $listItem .= " - three";
      }
  }
  </code></pre>