fesja
fesja

Reputation: 3313

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 remove 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!

Upvotes: 0

Views: 250

Answers (2)

dockeryZ
dockeryZ

Reputation: 3981

There's also array_splice()

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382796

Try this instead:

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

Upvotes: 1

Related Questions