Skip to content

Instantly share code, notes, and snippets.

@GlauberF
Last active July 22, 2022 17:08
Show Gist options
  • Save GlauberF/46f14d9da3074811e096f7e6bdbb2fc2 to your computer and use it in GitHub Desktop.
Save GlauberF/46f14d9da3074811e096f7e6bdbb2fc2 to your computer and use it in GitHub Desktop.
simple piped data generator. #gerador_table_php
/**
* Table Print
* @example
* echo TablePrinter("|%-15.15s |%-35.35s | x |\n", ['Author', 'Description'], [['Gauber Funez', 'simple piped data generator']]);
*/
function TablePrint(string $mask, array $header, array $data): string {
if (!$mask) {
throw new Exception("Não foi enviado a Máscara | TablePrinter", 1);
}
if (!$header || empty($header) || !is_array($header)) {
throw new Exception("Header não informado ou inválido", 1);
}
if (!$data || empty($data) || !is_array($data)) {
throw new Exception("Dados não informado ou inválido", 1);
}
$tPrinter = null;
$tPrinter = sprintf($mask, ...$header);
foreach ($data as $line) {
$tPrinter = $tPrinter."".sprintf($mask, ...$line);
}
return $tPrinter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment