Table
in package
Console table class
Tags
Table of Contents
Properties
- $h : string
- Horizontal border character
- $headerBg : int|null
- Header row background color
- $headerFg : int|null
- Header row foreground color
- $headers : array<string|int, mixed>
- Table headers
- $rows : array<string|int, mixed>
- Table rows
- $v : string|null
- Vertical border character (null omits vertical dividers)
Methods
- __construct() : mixed
- Instantiate the table object
- addRow() : Table
- Add a row to the table
- render() : string
- Render the table
- setHeaderColor() : Table
- Set the header row color
- setHeaders() : Table
- Set the table headers
- setRows() : Table
- Set the table rows
- buildBorderRow() : string
- Build a horizontal border row
- buildDataRow() : string
- Build a header or data row
- getColumnWidths() : array<string|int, mixed>
- Calculate the column widths from raw (uncolored) header/row content
Properties
$h
Horizontal border character
protected
string
$h
= '-'
$headerBg
Header row background color
protected
int|null
$headerBg
= null
$headerFg
Header row foreground color
protected
int|null
$headerFg
= null
$headers
Table headers
protected
array<string|int, mixed>
$headers
= []
$rows
Table rows
protected
array<string|int, mixed>
$rows
= []
$v
Vertical border character (null omits vertical dividers)
protected
string|null
$v
= '|'
Methods
__construct()
Instantiate the table object
public
__construct([array<string|int, mixed> $headers = [] ][, array<string|int, mixed> $rows = [] ][, string $h = '-' ][, string|null $v = '|' ]) : mixed
Parameters
- $headers : array<string|int, mixed> = []
- $rows : array<string|int, mixed> = []
- $h : string = '-'
- $v : string|null = '|'
addRow()
Add a row to the table
public
addRow(array<string|int, mixed> $row) : Table
Parameters
- $row : array<string|int, mixed>
Return values
Tablerender()
Render the table
public
render() : string
Return values
stringsetHeaderColor()
Set the header row color
public
setHeaderColor(int|null $fg[, int|null $bg = null ]) : Table
Parameters
- $fg : int|null
- $bg : int|null = null
Return values
TablesetHeaders()
Set the table headers
public
setHeaders(array<string|int, mixed> $headers) : Table
Parameters
- $headers : array<string|int, mixed>
Return values
TablesetRows()
Set the table rows
public
setRows(array<string|int, mixed> $rows) : Table
Parameters
- $rows : array<string|int, mixed>
Return values
TablebuildBorderRow()
Build a horizontal border row
protected
buildBorderRow(array<string|int, mixed> $widths) : string
Parameters
- $widths : array<string|int, mixed>
Return values
stringbuildDataRow()
Build a header or data row
protected
buildDataRow(array<string|int, mixed> $cells, array<string|int, mixed> $widths[, bool $isHeader = false ]) : string
Parameters
- $cells : array<string|int, mixed>
- $widths : array<string|int, mixed>
- $isHeader : bool = false
Return values
stringgetColumnWidths()
Calculate the column widths from raw (uncolored) header/row content
protected
getColumnWidths() : array<string|int, mixed>