开发者

foreach returns more elements than count()

I'm using Symfony 1.2.7 and Doctrine 1.1. I have $activities (sfOutputEscaperIteratorDecorator - Doctrine_Collection). I'm escaping everything on settings.yml with ESC_SPECIALCHARS method. If I weren't escaping it, it would work without any problem, so I think the problem is related with sfOutputEscaperIteratorDecorator.

If I do echo count($activities) it returns me 5

I re开发者_如何学运维move several elements:

foreach($activities as $key => $a){
  if(...){
    $activities->remove($key);
  }
}

Then if I do echo count($activities) it returns me 2

However when I iterate through the elements, I still have the same 5 elements:

foreach($activities as $activity){
  ..
}

Any idea?

thanks!


Try this instead:

foreach($activities as $key => $a){
  if(...){
    unset($activitie[$key]);
  }
}


There's also array_splice()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜