In this example i am reading in data from a text file and then I am outputting the data bases on whether the data is from a male or a female into a table. I am having trouble with the line: echo " $male_votes['class-int']"; I am receiving a parse error. I am just trying to access the first element in the array $male_votes with is named "class-int".
<?php
//Keep track of male votes
$male_votes =array("class-int" => 0, "class-gui" => 0, "class-net" => 0, "class-oop"=> 0);
//Keep track of the female votes
$female_votes = array("class-int" => 0, "class-gui" => 0, "class-net" => 0, "class-oop" => 0);
//Open the file for reading
$myfile = fopen("results.txt", "r") or die("Unable to open file!");
echo "<table border='1'>";
echo "<tr> <th> <strong> Class </strong> </th>";
echo "<th> <strong> Males </strong> </th>";
echo "<th> <strong> Females <strong> </th>";
echo "<th> <strong> Total </strong> </th> </tr>";
echo "<tr> <td> Internet Development </td>";
// Output one line until end-of-file
while(!feof($myfile)) {
//Read a single line from the file
$line = fgets($myfile);
//Make sure we didn't read an empty line
if(strlen($line) >0)
{
$class = substr($line,0,9);
$gender = substr($line,10,1);
echo "$class<br>";
if($gender == 'M')
{
$male_votes[$class]++;
}
else
{
$female_votes[$class]++;
}
}
}
echo "<td> $male_votes['class-int']</td>";
// echo"<td> $male_votes[$class] </td>";
// echo"<td> $female_votes[$class]</td>";
// echo "<td> $male_votes[$class] + $female_votes[$class]";
fclose($myfile);
?>