title: Use function only once inside a foreach loop
body: <p>I have a MySQL DB field populated with some data. I have an option in my script which cleans that field so I can add new fresh data to it without appending to the old stuff.</p>
  
  <p>However I am using a foreach loop which looks like this:</p>
  
  <pre><code>            foreach ($model-&gt;filenames as $key =&gt; $model-&gt;filename) {
              $model-&gt;get_title($model-&gt;filename);
              $model-&gt;get_showTitle($model-&gt;titles);
              $model-&gt;get_number($model-&gt;titles);
              $model-&gt;get_host($model-&gt;urls[$key]);
              $model-&gt;source_title($model-&gt;titles);
              $model-&gt;get_season();
              if ($model-&gt;show_exist_batch()) {
                  $model-&gt;show_clean(); //the method in question
                  $model-&gt;show_update();
              } else {
                  $model-&gt;show_add();
                  $model-&gt;twitter();
              }
  </code></pre>
  
  <p>The thing is that I want show_clean() to only run ONCE. 
  This is how show_clean() looks:</p>
  
  <pre><code>    public function show_clean() {
      if ($this-&gt;options-&gt;clean) {
          $query = "UPDATE jos_k2_items SET extra_fields = '', extra_fields_search = '' WHERE id = " . $this-&gt;item-&gt;id . "";
          $this-&gt;db-&gt;prepare($query);
          $this-&gt;db-&gt;query();
      }
  }
  </code></pre>
  
  <p>$this->option->clean is set by a post variable in the constructor.</p>
  
  <p>Are there any clever ways of doing this or do i need to do it the long way?</p>