Let's parse this loop:
<b>
for ($B = 0;$B <= count($ThisRow);$B++){
$ThisRow[$B] = trim($ThisRow[$B]);
}
</b>
Just for fun, let's assume that $ThisRow starts with one element in it. At the start of your loop:
$B is set to 0
$count($ThisRow) evaluates to 1
zero IS less than or eqaul to 1 so your loop goes ahead and trims $ThisRow[0]. So far, so good.
But the structure of the for loop dictates that $B gets incremented ($B++) so now:
$B is set to 1
$count($ThisRow) evaluates to 1
1 IS STILL less than OR EQAUL TO 1 so your loop goes ahead and trims $ThisRow[1].
"BUT WAIT! I DON'T HAVE A $ThisRow[1]!" you say. Well, you DO NOW! So:
$B gets incremented to 2
$count($ThisRow) evaluates to... <b>2!</b>
2 IS STILL less than OR EQAUL TO 2 so your loop goes ahead and trims $ThisRow[2].
"BUT WAIT! I DON'T HAVE A $ThisRow[2]!" you say. Well, you DO NOW! So:
$B gets incremented to 3
$count($ThisRow) evaluates to... <b>3!</b>
3 IS STILL less than OR EQAUL TO 3 so your loop goes ahead and trims $ThisRow[3].
"BUT WAIT! I DON'T HAVE A $ThisRow[2]!" you say. Well, you DO NOW! So...
...Are you getting the picture?
Generally, it is never a good idea to use an evaluation in a loop control; especially an evaluation of a variable that gets modified inside the loop.
Instead, use:
<b>
$numElements = count($ThisRow);
for ($B = 0; $B<$numElements; $B++){
$ThisRow[$B] = trim($ThisRow[$B]);
</b>
HTH
--Rich