title: PHP - Can't get matched value from foreach loop
body: <p>I'm trying to make a loop that will detect if you've entered a banned username. But I want to report back to the user what match was made to determine what keyword was used to ban the name. Do you see anything wrong with this?</p>
  
  <pre><code>function matchusername($bannedusername, $username)
  {
      foreach($bannedusername as $bannedusernam =&gt; $value){
          if (strpos($username, $bannedusernam) !== false) {
              $offendingusername = $value;
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>I have some more code that'll check for a valid comment as well and some other various things. </p>
  
  <p>When I add the <code>=&gt;</code> <code>$value</code> and <code>$offendingusername = $value;</code> it seems to just break that loop and skips it and allows the user to post anyway. When I take those 2 parts away, it'll detect a banned username and not allow you to post like it should, but I'd really like it to report the matched value back so in case the users writing a long comment, they can see why they can't post.</p>
  
  <p>I've looked at a lot of other sources and this looks to be the way to do it but it's not working. Any ideas? Thank you.</p>