Last active
July 22, 2022 17:08
-
-
Save GlauberF/46f14d9da3074811e096f7e6bdbb2fc2 to your computer and use it in GitHub Desktop.
simple piped data generator. #gerador_table_php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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