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