title: Limit output in foreach
body: <p>I want to check in an xml file with CDATA if cities exist.
  If the cities exist one or more time, then I want to display an input.</p>
  
  <p>I have found several ways to check if the city exists or not, however as it exists several times it display several times.</p>
  
  <p>Both ways below prints out correctly, but I need only one output:</p>
  
  <pre><code>foreach($paradasarray as $parada){
      if (substr_count($parada-&gt;localidad, 'Benalmádena') &gt; 0) {
          echo 'Benalmádena Costa';
      }
      if (strpos($parada-&gt;localidad, 'Benalmádena') !== false) {
          echo 'Benalmádena Costa';
      }   
  }
  
  Both ways outputs like this:
  Benalmádena CostaBenalmádena CostaBenalmádena CostaBenalmádena 
  CostaBenalmádena CostaBenalmádena CostaBenalmádena CostaBenalmádena 
  CostaBenalmádena CostaBenalmádena CostaBenalmádena CostaBenalmádena 
  CostaBenalmádena CostaBenalmádena CostaBenalmádena CostaBenalmádena 
  CostaBenalmádena CostaBenalmádena CostaBenalmádena CostaBenalmádena 
  </code></pre>