I am trying to add elements in a flat text file and count how many there are!
$filename = "tickets/TICKETS.DAT";
$size = filesize($filename);
$handle = fopen($filename, "r");
while (!feof($handle)) {
$contents .= fread($handle, $size);
$ticketcount = preg_match_all('/([0-9]{2,3})\.([0-9]{2})/', $contents,$matches);
if (preg_match_all('/([0-9]{2,3})\.([0-9]{2})/',$contents,$tickets)){
$result = array("$tickets");
}
}
echo "Sum of values = ".array_sum($tickets)."<br>";
print "$ticketcount Tickets";
The TICKET.DAT looks like this:
60.00
40.00
20.00
80.00
100.00
The output is looking like this:
Sum of values = 0
5 Tickets
How do add values in the array? if it is an array? ... I hate arrays...
Please help..