title: How to break out of a foreach once a condition is met?
body: <p>I have a situation where when dealing with an object I generally use a foreach to loop through it like this:</p>
  
  <pre><code>foreach ($main_object as $key=&gt;$small_object) {
  ...
  
  }
  </code></pre>
  
  <p>However, I need to put a conditional in there like this:</p>
  
  <pre><code>foreach ($main_object as $key=&gt;$small_object) {
     if ($small_object-&gt;NAME == "whatever") {
        // We found what we need, now see if he right time.
        if ($small_object-&gt;TIME == $sought_time) {
            // We have what we need, but how can we exit this foreach loop?
        }
  }
  </code></pre>
  
  <p>What is the elegant way to do this? It seems wasteful to have it keep looping through if it's found a match. Or is there another approach to do this that is better? Possibly using for instead of foreach? </p>