title: How can I have a loop run until I have a select number of results?
body: <p>IN PHP: I have a for loop running through an array and if the value of each key does not match the value I'm looking for, I skip it.</p>
  
  <p>How can I create a loop that runs until I have found 20 of the values that I am looking for.  So I can't have it be <code>for($i=0;$i&lt;50;$i++)</code> because of the first 50, there may be only 2 values that match.  So it needs to run until 20 match.</p>
  
  <p>UPDATE: I also need to iterate through the array, so I still need to check every value like this: $news_posts[$i]['category'];  if category is what i'm looking for then that's 1.  If its not, then I skip it.  I need 20.</p>