I'm stuck. I want to read in a cvs comma delimited file into an array.
The data looks like this
1, 1,10
1, 2, 9
1, 3, 8
1, 4, 7
1, 5, 6
when I print the array out its first entry is 1,2,9 instead of 1,1,10. print_r verifies that 1,1,10 is there--so something must be wrong with my for loop (I also tried a while loop, same problem) but I'll be darn if I can figure out where the problem is.
Here's the code
$thisPass = 0;
if (($handle = fopen("10Teams.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
// print "value of this pass is $thisPass ";
if($thisPass ==0)
{$meetNum=$data[$c];
}
if($thisPass ==1)
{
$teamA=$data[$c];
}
if($thisPass ==2)
{
$teamB=$data[$c];
$addToArray=1;
}
$thisPass++;
//print "add to array is $addToArray <br/>";
if($addToArray ==1)
{$match[$i]=array($meetNum, $teamA, $teamB);
$addToArray = 0;
$thisPass = 0; $i++;
}
}
}
fclose($handle);
}
print "print array <br/>" ;
for($i=0; $i < 45; $i++) {
list($timeSlot,$teamA,$teamB) = $match[$i];
echo $timeSlot . " " . $teamA . " " . $teamB ."<br/>";
}
echo "print r routine <pre>";
print_r($match);
echo "</pre>";
thanks!
Bob