[ciapug] counting array elements using count()
Darcy Baston
ciapug@cialug.org
Fri, 06 May 2005 09:50:22 -0500
Hi guys, TGIF!
My brain's not working today. I've been using count() for counting array elements for several weeks and all of a sudden, it's giving me parse errors?
I have an array called Products. It's two dimensional. Results come from a MySQL query that is returning results. It looks like this:
Products[0][0] = "ProductGroupName"
Products[0][1] = "someIDnumber"
Products[0][2] = "someIDnumber"
Products[0][3] = "someIDnumber"
...
Products[1][0] = "ProductGroupName"
Products[1][1] = "someIDnumber"
Products[1][2] = "someIDnumber"
Products[1][3] = "someIDnumber"
...
What I'm having trouble with that's generating parse errors is:
$variable = sizeof($Products[0]);
If I comment that line out, everything works/runs fine. Put it back in and parse error is triggered.
I've done that before with a variable that loads records line by line from a CSV ile using something like:
foreach($lines as $field){
$allFields[]=Explode($separator, $field);
}
$lineCount=sizeof($allFields); // counts lines
$fieldCount=sizeof($allFields[0]); // counts columns in first row
Without generating any parse errors, and it works just great. So why am I getting parse errors the other way to do you think?
PHP 4.3.2
MySQL 3.23.58
Darcy