Skip to content

Instantly share code, notes, and snippets.

@kastaneda
Created August 17, 2020 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kastaneda/4bca366b3da122f61ba3944e4bbeb448 to your computer and use it in GitHub Desktop.
Save kastaneda/4bca366b3da122f61ba3944e4bbeb448 to your computer and use it in GitHub Desktop.
<?php
$tsv = "foo\t100\t150\nbar\t120\t200\nquux\t115\t180\n";
echo $tsv;
$table = array_map(fn($row) => explode("\t", $row), explode("\n", trim($tsv)));
print_r($table);
echo implode("\n", array_map(fn($row) => implode("\t", $row), $table)) . "\n";
@kastaneda
Copy link
Author

// Transpose
$table = array_map(null, ...$table);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment