 <p>Try putting in a break.</p> <pre><code>// As a side note: you can check at the very beginning to see that // the ID isn't being compromised by something by checking if // is_numeric. Also, you can save your 'fail' message until the very // end when checking that your $leadsource isset. These extra points // are not essential, but they will throw a fail at all points of the // code (if that is valuable at all to you) $sourcetracking = (isset($_GET['id']) &amp;&amp; is_numeric($_GET['id']))? $_GET['id']:false; if($sourcetracking !== false) { $LegacyIDLookupArray = array( '2612' =&gt; 'ADV-ShowProg', '2462' =&gt; 'ADV-ShowProg-3.5x7', '2422' =&gt; 'ADV-Mag-book' ); foreach ($LegacyIDLookupArray as $LegacyID =&gt; $Oldleadsource) { if($sourcetracking == $LegacyID) { $leadsource = &amp;$Oldleadsource; // This is where the break goes to stop your loop // when condition is met break; } } } // Your $leadsource OR fail is echoed here. echo (isset($leadsource))? $leadsource : "fail"; </code></pre>