#!/usr/bin/env php 1) { $args = $GLOBALS['HTTP_SERVER_VARS']['argv']; $script = array_shift($args); } else { die("Enter the filename"); } $options = array( 1 => 'Just Before', 2 => 'Just After', 3 => 'Week Before', 4 => 'Week After', ); $ordinal_numbers = array( 0 => '1st', 1 => '2nd', 2 => '3rd', 3 => '4th', ); $votes_by_order = array(); foreach (file($args[0]) as $line) { for ($order = 0; $order < 4; $order++) { if ($vote = (int)substr($line, $order, 1)) { $votes_by_order[$order][$vote]++; $votes_by_option[$vote][$order]++; } } } foreach ($votes_by_order as $key => $discard) { arsort($votes_by_order[$key]); } foreach ($votes_by_option as $key => $discard) { ksort($votes_by_option[$key]); } foreach ($votes_by_order as $order => $counts) { if ($order > 1) break; print "In {$ordinal_numbers[$order]} place there were;\n"; $i = 0; foreach ($counts as $option => $count) { if ($i > 1) break; $i++; print " $count votes for " . $options[$option] . "\n"; } } print "\n"; foreach ($votes_by_option as $option => $counts) { print "Votes for {$options[$option]} put it in;\n"; foreach ($counts as $order => $count) { print " {$ordinal_numbers[$order]} place $count times\n"; } }