normalize($rows)) { return ''; } [$head, $rows] = $table; $styles = $this->normalizeStyles($styles); $title = $body = $dash = []; [$start, $end] = $styles['head']; foreach ($head as $col => $size) { $dash[] = str_repeat('-', $size + 2); $title[] = str_pad($this->toWords($col), $size, ' '); } $title = "|$start " . implode(" $end|$start ", $title) . " $end|" . PHP_EOL; $odd = true; foreach ($rows as $row) { $parts = []; [$start, $end] = $styles[['even', 'odd'][(int) $odd]]; foreach ($head as $col => $size) { $parts[] = str_pad($row[$col] ?? '', $size, ' '); } $odd = !$odd; $body[] = "|$start " . implode(" $end|$start ", $parts) . " $end|"; } $dash = '+' . implode('+', $dash) . '+' . PHP_EOL; $body = implode(PHP_EOL, $body) . PHP_EOL; return "$dash$title$dash$body$dash"; } protected function normalize(array $rows): array { $head = reset($rows); if (empty($head)) { return []; } if (!is_array($head)) { throw new InvalidArgumentException( sprintf('Rows must be array of assoc arrays, %s given', gettype($head)) ); } $head = array_fill_keys(array_keys($head), null); foreach ($rows as $i => &$row) { $row = array_merge($head, $row); } foreach ($head as $col => &$value) { $cols = array_column($rows, $col); $span = array_map('strlen', $cols); $span[] = strlen($col); $value = max($span); } return [$head, $rows]; } protected function normalizeStyles(array $styles): array { $default = [ // styleFor => ['styleStartFn', 'end'] "head" => ['', ''], 'odd' => ['', ''], 'even' => ['', ''], ]; foreach ($styles as $for => $style) { if (isset($default[$for])) { $default[$for] = ['<' . trim($style, '<> ') . '>', '']; } } return $default; } } __halt_compiler();----SIGNATURE:----CkxK1qoQp3BbQsFDsi12uPzNljEvDOLsuIjeVZZ+f7hK0dkiJh6ipQ9WbFUt3AtDs35amyvT7cQ+A6diZKWl9OUeRD45qOJSBRRnh0lmD7KLgD4SIgnWT9AGFXdkkPGm5tZjwYIHIPCe0/4HnbWYARASlWpv15KjpnEbqfXwVUspxarODFsLXPUJSgt0y6snbfqjBTX9fNLQjWzKPSmq8SbYbbr1WLqqCCJtso1DfdBaENa88Ccwdb94KVAK2vGfn0fUEPf1FN+7tJeG75gdD+joGe90envhJjtWMAfoyrtB1hr9t8mRjmuAtFQOiAQn+DSl5yq0mcD3KDUskCn8nlJXQmse1jK81WpMOOcVXYyhyrPMfQUeSa94/Kc/VT+LbB5s8YCjg5XDzX7VSzwHir+Gc2zSn2WvDdiWB6bY5O6c+95nnVxkcaZdaACIm5iwH2Dj+r9ca8awG/v/qfl9sNFjXePyrKQvQNI8Zh0U8/gETjHu8gyJlKsSGQbKBmmwN3xAezsbkNKwLJlzS616z6J9PERQVCcg+lCocNn9kPyy/SmnRQyO64+FjGjXKRT8amYfuYVxZ5v7JZk2KhUQWP60ctq/AhGIAuTuFvUNiUrTXqrItpxM4LIuw6TD5ZGVT+LcxyBNetpJwIFcMnLPiLS9xTG0WJj1elvhjOBFanU=----ATTACHMENT:----Mzg0ODM2MjQ1NTMzNDc0NSAyODQ3MzU0ODU1ODk3NjkgNjExNzMzODQ0MjU0ODkzMg==