title: Stop processing and evaluate next value in foreach loop
body: <p>I am trying to search and check for the duplicate details that is available in the database using php.The user enters several names and then a phone number to check for the duplicates. Below is my function. I just cropped out some parts because it was too long.</p>
  
  <pre><code>function gtc($names,$phone)
  {
  
      $pageNumb=20;
      $position = array(5);
  
      $sepname=explode(",","$names");
  
  foreach ($sepname as $sepname1)
  {
      for ($page=0;$page&lt;=$pageNumb;$page=$page + 1)
      {
      $turl="http://192.168.111.2119/search.php?qry=$sepname1&amp;page=$page";
  
      $search=curl_init();
  
      curl_setopt($search,CURLOPT_URL,$turl);
      curl_setopt($search,CURLOPT_RETURNTRANSFER,1);
      curl_setopt($search,CURLOPT_FAILONERROR,true);
      curl_setopt($search,CURLOPT_AUTOREFERER,true);
      $result=curl_exec($search);
  
          $dom = new DOMDocument();
          @$dom-&gt;loadHTML($result);
  
          $xpath=new DOMXPath($dom);
          $elements = $xpath-&gt;evaluate("//div[@id='inf']");
  
          foreach ($elements as $element)
          {
  
              $position[$sepname1] = $position[$sepname1] + 1;
  
              foreach($position as $key=&gt;$val)
  
              $contct  = $element-&gt;getElementsByTagName("contact")-&gt;item(0)-&gt;nodeValue;
  
              if (preg_match("/$phone/i",$contct)) {
                  echo "Found In Database&gt;";
  
              }
  
              }
  
          ob_flush();
          flush();
  
          }
  }
      }
  
  
  ?&gt;
  </code></pre>
  
  <p>The function works perfectly but the only problem that I am having is although a match is found it goes until the last page which is given in the for loop and then goes through the next name. I would like to know is it possible to make when a match is found stop processing and then search for the next name?</p>
  
  <p>I don’t want to use exit(); because it completely stops the execution</p>
  
  <p>The input format is as below<br>
  User inputs names: john, Sam, Michael, Steve<br>
  Phone number:0084554741<br></p>
  
  <p>Any help will be appreciated</p>