title: How to stop adding new values to an array after one value is added to that array?
body: <p>I have some html files that contain the same tags with different strings between these tags , I want to get strings from specific tags and after it finds the first match then this string is the only added to the array , for more details see this code.</p>
  
  <p>The html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;&lt;/head&gt;
    &lt;body&gt;
      &lt;h1&gt;Some Text&lt;/h1&gt;
      &lt;p&gt;This is the first Paragraph&lt;/p&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;/li&gt;
        &lt;li&gt;&lt;/l1&gt;
      &lt;/ul&gt;
      &lt;p&gt;This is the second Pharagraph&lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>The html files will contain more elements</strong></p>
  
  <p>I want to get the text inside the first <code>&lt;p&gt;</code> only and prevent wasting time searching the whole html file while I just want to get one value from a specific tag.</p>
  
  <p>The PHP:</p>
  
  <pre><code>//Loop inside all the HTML files inside a folder
  $files = glob("files/*.html");
  foreach($files as $file){ 
      //Get the whole content of each HTMl file
      $content = file_get_contents($file);
      //Search for specific tag
      preg_match_all('#&lt;p&gt;(.*?)&lt;\/p&gt;', $content, $matches);
  }
  </code></pre>
  
  <p>I only want to add the value of the first match to the <code>$matches</code>.</p>
  
  <p><strong>I can't edit the html code to add class or id to the tags I want to get values from because I'm not the one who created them and I can't edit all the files manually</strong></p>
  
  <p><strong>I don't mind using another way to get these values but it should achieve what I want (only the first match then it's stopped searching the whole file)</strong></p>