title: Perform PHP loops until end of array OR reaches certain number of iterations?
body: <p>I wish to receive one array as input, filter values from it, and output as another array. The function should loop through up to <code>x</code> iterations.</p>
  
  <p>For example, if I wanted to output <strong>all</strong> the values from the input, I would use:</p>
  
  <pre><code>&lt;?php
  $i=0;
  foreach ($array as $data) {
      if ($data['type'] != 'some_value') {
          $formatted_array[$i] = $data;
          $i++;
      }
  }
  return $formatted_array;    
  </code></pre>
  
  <p>But if <code>$array</code> had a large index, the <code>$formatted_array</code> would be larger than I need. I tried using a <code>for</code> loop with multiple conditions, but it seems to get stuck in an infinite loop.</p>
  
  <p>I'm not a developer by trade, so the logic is difficult to comprehend. I'm not getting errors, so it's hard to understand where exactly I'm going wrong.</p>
  
  <p>How can I perform PHP loops until end of array or until the function reaches certain number of iterations?</p>