Skip to content

Instantly share code, notes, and snippets.

@GlauberF
Last active Jul 22, 2022
Embed
What would you like to do?
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