the second version, when everything to do with $s++ and $s-- is removed, doesn't iterate enough times.
when the lines with $s are inserted, it goes through to many times and acts upon the wrong data sets. basically I'm asking: how do I replace the foreach loops with for loops?