title: foreach in foreach overwrite result
body: <p>here is my PHP code: <a href="https://eval.in/871659" rel="nofollow noreferrer">https://eval.in/871659</a></p>
  
  <p>1- I have some HTML codes with javascript <code>$content</code> <strong>line 2</strong></p>
  
  <p>2- I want to extract javascript codes to array <strong>line 17</strong></p>
  
  <p>3- I have some allow list array <code>$allowed_js</code> (the javascript codes that can be on my HTML) <strong>line 20</strong></p>
  
  <p>4- I want to remove not allowed javascript <strong>line 26 - 35</strong></p>
  
  <p>The problem is in section 4, because I am using foreach in foreach, every javascript <code>$matches array</code> check as count as <code>$allowd_js array</code> which is true, </p>
  
  <p>but the problem is it's it's get replace string if it detects not allowed string, so basically for every javascript, there is only one allowed word (that contained in <code>$allowed_js array</code>), so in every case it's will be replaced</p>
  
  <p>I also tried using <code>break</code> but it's not working</p>
  
  <p>also, i tried this loop, but it's not working too</p>
  
  <pre><code>$allow_count = count($allowed_js)-1;
  foreach ($matches[0] as $key =&gt; $value) {
  for ($i = 0; $i &lt;= $allow_count ; $i++) {
          if (strpos($value,$allowed_js[$i]) == false) {
              $content = str_replace($value,"",$content);
              //break;
          }
  
      }
  }
  </code></pre>