function read_input($filename, $delimiter) { $dialect = new Csv_Dialect(); $dialect->delimiter = $delimiter; try { $reader = new Csv_Reader($filename, $dialect); } catch (Exception $e) { print_error_and_exit('Could not open the specified input file'); } $rows = $reader->toArray(); return $rows; }
function build_tree($cases) { $top_sections = array(); $count = 0; foreach ($cases as $case) { // Find the sections for this case if (isset($case['section']) && $case['section']) { $section_names = preg_split('/\\>/', $case['section']); $section_names = array_map('trim', $section_names); if (count($section_names) == 0) { print_error_and_exit("Case {$count} has no sections defined."); } } else { $section_names = array('Unnamed'); } // Find/build the sections and attach the case $current_sections =& $top_sections; foreach ($section_names as $name) { $key = strtolower($name); if (!isset($current_sections[$key])) { $current_sections[$key] = new stdClass(); $current_sections[$key]->sections = array(); $current_sections[$key]->cases = array(); $current_sections[$key]->name = $name; } $current_cases =& $current_sections[$key]->cases; $current_sections =& $current_sections[$key]->sections; } $current_cases[] = $case; $count++; } return $top_sections; }