title: PHP: foreach looping too many times
body: <p>The get_tag_id is bringing back the first array item twice if I enter the following:</p>
  
  <p>texture, clients</p>
  
  <p>I get this return:</p>
  
  <pre><code>Array
  (
      [0] =&gt; texture
      [1] =&gt; clients
  )
  Array
  (
      [0] =&gt; stdClass Object
          (
              [TagID] =&gt; 4
              [Title] =&gt; texture
          )
  
  )
  Array
  (
      [0] =&gt; stdClass Object
          (
              [TagID] =&gt; 4
              [Title] =&gt; texture
          )
  
  )
  Array
  (
      [0] =&gt; stdClass Object
          (
              [TagID] =&gt; 1
              [Title] =&gt; clients
          )
  
  )
  Array
  (
      [0] =&gt; texture
      [1] =&gt; clients
  )
  </code></pre>
  
  <p>Below is the code:</p>
  
  <pre><code>        // Break up Tags and Store in an Array
          $delimiter = " ";
          $tags = explode($delimiter, $this-&gt;input-&gt;post('tags'));
  
          // Remove Accidential Spaces if any.
          $tags = array_filter($tags, function($var){
               return preg_match('/^[a-z-]+$/i', $var);
          });
  
          // Create Arrays for Seperation
          $newTags = array();
          $currentTags = array();
          print_r($tags);
  
          // Check if Tags Exists
          foreach ($tags as $tag) 
          {
              if (!$this-&gt;Bookmark_model-&gt;tag_exists($tag))
              {
                  array_push($currentTags, strtolower($tag));
                  // Get ID of tags that are existing
                  foreach ($currentTags as $tagname) 
                  {
                      $id = $this-&gt;Bookmark_model-&gt;get_tag_id($tagname);
                      echo $id;
                  }
              }
              else
              {
                  array_push($newTags, strtolower($tag));
              }
          }
  </code></pre>
  
  <p>get_tag_id() code:</p>
  
  <pre><code>function get_tag_id($tag)
  {
      // Load Database
      $this-&gt;load-&gt;database();
      // Query Database
      $this-&gt;db-&gt;where_in('Title', $tag);
          $query = $this-&gt;db-&gt;get('Tag', 1);
          $result = $query-&gt;result();
          // Return ID of Tag
          //return $result[0]-&gt;TagID;
          print_r($result);
  }
  </code></pre>