PHP library with zero dependencies that convert array data into ascii table.
Based on https://github.com/viossat/arraytotexttable.
- Zero dependencies (custom Decorator class).
- Numeric values are automatic aligned to right
- Optional limit for values (adding ellipsis
…
)
require 'phpArray2Table.php';
$data = [
[
'firstname' => 'Mollie',
'surname' => 'Alvarez',
'email' => '[email protected]',
],
[
'firstname' => 'Dianna',
'surname' => 'Mcbride',
'age' => 43,
'email' => '[email protected]',
],
[
'firstname' => 'Elvira',
'surname' => 'Mueller',
'age' => 5,
'email' => '[email protected]',
],
[
'firstname' => 'Corine',
'surname' => 'Morton',
'age' => 35,
],
[
'firstname' => 'James',
'surname' => 'Allison',
],
[
'firstname' => 'Bowen',
'surname' => 'Kelley',
'age' => 50,
'email' => '[email protected]',
]
];
$renderer = new phpArray2Table($data);
echo $renderer->getTable();
prints:
┌───────────┬─────────┬───────────────────────────┬─────┐
│ FIRSTNAME │ SURNAME │ EMAIL │ AGE │
├───────────┼─────────┼───────────────────────────┼─────┤
│ Mollie │ Alvarez │ [email protected] │ │
│ Dianna │ Mcbride │ [email protected] │ 43 │
│ Elvira │ Mueller │ [email protected] │ 5 │
│ Corine │ Morton │ │ 35 │
│ James │ Allison │ │ │
│ Bowen │ Kelley │ [email protected] │ 50 │
└───────────┴─────────┴───────────────────────────┴─────┘
$renderer->setValueMaxLength(10);
prints:
┌───────────┬─────────┬─────────────┬─────┐
│ FIRSTNAME │ SURNAME │ EMAIL │ AGE │
├───────────┼─────────┼─────────────┼─────┤
│ Mollie │ Alvarez │ molliealva… │ │
│ Dianna │ Mcbride │ diannamcbr… │ 43 │
│ Elvira │ Mueller │ elviramuel… │ 5 │
│ Corine │ Morton │ │ 35 │
│ James │ Allison │ │ │
│ Bowen │ Kelley │ bowenkelle… │ 50 │
└───────────┴─────────┴─────────────┴─────┘