/** * This is being run to do stuff. */ function main($argv) { $input = $argv[1]; $csv = readCsvFile($input); $persons = transcode($csv); $groups = []; $counts = []; foreach ($persons as $k => $p) { $others = array_diff_key($persons, [$k => $p]); // remove person to avoid duplicate in group $group = createGroupFor($p, $others, $counts); $groups[] = $group; } saveIntoCsvFile($argv[2], $groups); }
$product = mapProduct($columns, getMapping()); $products[] = $product; } return $products; } function mapProduct($columns, $mapping) { $product = []; foreach ($columns as $key => $value) { if (isset($mapping[$key + 1])) { $attribute = $mapping[$key + 1]; $product[$attribute] = $value; } } return $product; } function writeToStorage($products) { // извращение :) $filesContents = array_map(function ($product) { $contents = ''; foreach ($product as $key => $value) { $contents .= sprintf("%s:%s\n", $key, $value); } return $contents; }, $products); var_dump($filesContents); } $lines = readCsvFile('products.csv'); $products = parseData($lines); writeToStorage($products);