title: Strange variable overwrite in foreach loop
body: <p>This must be something ugly obvious, but I'm stucked on this and can't solve it for past two hours.</p>
  
  <p>I have this piece of code:</p>
  
  <pre><code>foreach($idMap as $menuId=&gt;$pageId)
  {
      echo('$this-&gt;update("menus_items", SET "link = /content/show?id='.$pageId.'" WHERE id = '.$menuId.');'."\n");
  
      $this-&gt;update
      (
          'menus_items',
          array('link'=&gt;'/content/show?id='.$pageId),
          array('id = '.$menuId)
      );
  }
  </code></pre>
  
  <p><code>echo</code> part works as expected (<code>$pageId</code> is different for each item, taken from <code>$idMap</code>), while Yii's <a href="http://www.yiiframework.com/doc/api/1.1/CDbCommand/#update-detail" rel="nofollow"><code>CDbCommand::update()</code></a> gets wako and have <code>$pageId</code> equal to it's last value for all loop iterations.</p>
  
  <p>In other words, if I have 20 menu items and last item in result set has <code>pageId</code> = <code>18</code>, then when using <code>CDbCommand::update()</code>, I'm getting <em>all</em> menu items set to that last value.</p>
  
  <p>There must be some variable overwriting here, but I can't find it for past two hours, especially, that <code>echo</code> put just one line above works great. Can someone help here.</p>