Documentation

Table
in package

Console table class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
5.0.0

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
Table

render()

Render the table

public render() : string
Return values
string

setHeaderColor()

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
Table

setHeaders()

Set the table headers

public setHeaders(array<string|int, mixed> $headers) : Table
Parameters
$headers : array<string|int, mixed>
Return values
Table

setRows()

Set the table rows

public setRows(array<string|int, mixed> $rows) : Table
Parameters
$rows : array<string|int, mixed>
Return values
Table

buildBorderRow()

Build a horizontal border row

protected buildBorderRow(array<string|int, mixed> $widths) : string
Parameters
$widths : array<string|int, mixed>
Return values
string

buildDataRow()

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
string

getColumnWidths()

Calculate the column widths from raw (uncolored) header/row content

protected getColumnWidths() : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results