View Single Post
  #7  
Old 12-16-2008, 09:03 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Probably because you're deleting entrys in an array currently used for the loop, thus messing it up. You should never manipulate the same array as the loop uses, use a copy of it and update the original after the loop


PHP Code:
temp.array = { "foo""bar""baz" };
for (
temp.entrytemp.array) {
  echo(
temp.entry);
  if (
temp.entry == "foo"temp.array.delete(temp.var);
  
temp.var ++;

Echoes "foo" and "baz" since by deleting an entry, you shorten the array, thus skipping "bar".

Instead, do something like:

PHP Code:
temp.array = { "foo""bar""baz" };
temp.loopArray temp.array;
for (
temp.entrytemp.array) {
  echo(
temp.entry);
  if (
temp.entry == "foo"temp.loopArray.delete(temp.var);
  
temp.var ++;
}
temp.array = temp.loopArray
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote