\n"; ?> $ranking) { ?> $name, 'gender' => $gender, 'rankings' => array_values($rankings) ); print json_encode($output); } // Extract and return the name, gender, and an array of the rankings // from the supplied line, in the names.txt file's format. function extract_data($line) { $tokens = explode(' ', $line); $name = array_shift($tokens); $gender = array_shift($tokens); $rankings = array(); $year = 1890; foreach ($tokens as $ranking) { $rankings[$year] = intval($ranking); $year += 10; } return array($name, $gender, $rankings); } ?>