2017 © Pedro Pelรกez
 

library arraytotexttable

Display arrays in terminal

image

mathieuviossat/arraytotexttable

Display arrays in terminal

  • Friday, August 21, 2015
  • by viossat
  • Repository
  • 1 Watchers
  • 25 Stars
  • 43,588 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 5 Versions
  • 8 % Grown

The README.md

ArrayToTextTable

Installation

composer require mathieuviossat/arraytotexttable
{
    "require": {
        "mathieuviossat/arraytotexttable": "~1.0.0"
    }
}

Example

use MathieuViossat\Util\ArrayToTextTable;

$data = [
    [
        'firstname' => 'Mollie',
        'surname' => 'Alvarez',
        'email' => 'molliealvarez@example.com',
    ],
    [
        'firstname' => 'Dianna',
        'surname' => 'Mcbride',
        'age' => 43,
        'email' => 'diannamcbride@example.com',
    ],
    [
        'firstname' => 'Elvira',
        'surname' => 'Mueller',
        'age' => 50,
        'email' => 'elviramueller@example.com',
    ],
    [
        'firstname' => 'Corine',
        'surname' => 'Morton',
        'age' => 35,
    ],
    [
        'firstname' => 'James',
        'surname' => 'Allison',
    ],
    [
        'firstname' => 'Bowen',
        'surname' => 'Kelley',
        'age' => 50,
        'email' => 'bowenkelley@example.com',
    ],
];

$renderer = new ArrayToTextTable($data);
echo $renderer->getTable();

Result

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”
โ”‚ FIRSTNAME โ”‚ SURNAME โ”‚           EMAIL           โ”‚ AGE โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Mollie    โ”‚ Alvarez โ”‚ molliealvarez@example.com โ”‚     โ”‚
โ”‚ Dianna    โ”‚ Mcbride โ”‚ diannamcbride@example.com โ”‚ 43  โ”‚
โ”‚ Elvira    โ”‚ Mueller โ”‚ elviramueller@example.com โ”‚ 50  โ”‚
โ”‚ Corine    โ”‚ Morton  โ”‚                           โ”‚ 35  โ”‚
โ”‚ James     โ”‚ Allison โ”‚                           โ”‚     โ”‚
โ”‚ Bowen     โ”‚ Kelley  โ”‚ bowenkelley@example.com   โ”‚ 50  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”˜

Options

$renderer->setData($newData);
// Accepts array of arrays and array of objects.
// Can also be called through getTable():
$renderer = new ArrayToTextTable();
echo $renderer->getTable($data);

$renderer->setDecorator(new \Zend\Text\Table\Decorator\Ascii());
// Unicode (default), Ascii, Blank

$renderer->setIndentation("\t");
// default: *empty string*

$renderer->setDisplayKeys(false);
// true, false, 'auto' (default, doesn't display keys if all of them are integers)

$renderer->setUpperKeys(false);
// default: true

$renderer->setKeysAlignment(ArrayToTextTable::AlignCenter);
// AlignLeft, AlignCenter (default), AlignRight

$renderer->setValuesAlignment(ArrayToTextTable::AlignLeft);
// AlignLeft (default), AlignCenter, AlignRight

$formatter = function(&$value, $key, $renderer) {
    if ($value === true)
        $value = 'TRUE';
    else if ($value === false)
        $value = 'FALSE';
    else if ($value === '')
        $value = 'EMPTY';
    else if ($value === null)
        $value = 'NULL';
};
$renderer->setFormatter($formatter);
// default: null

License

This library is published under The MIT License., (*1)

The Versions

21/08 2015

dev-master

9999999-dev https://github.com/MathieuViossat/arraytotexttable

Display arrays in terminal

  Sources   Download

MIT

The Requires

 

array terminal table text unicode ascii

21/08 2015

v1.0.3

1.0.3.0 https://github.com/MathieuViossat/arraytotexttable

Display arrays in terminal

  Sources   Download

MIT

The Requires

 

array terminal table text unicode ascii

10/07 2015

v1.0.2

1.0.2.0 https://github.com/MathieuViossat/arraytotexttable

Display arrays in terminal

  Sources   Download

MIT

The Requires

 

array terminal table text unicode ascii

07/07 2015

v1.0.1

1.0.1.0 https://github.com/MathieuViossat/arraytotexttable

Display arrays in terminal

  Sources   Download

MIT

The Requires

 

array terminal table text unicode ascii

06/07 2015

v1.0.0

1.0.0.0 https://github.com/MathieuViossat/arraytotexttable

Display arrays in terminal

  Sources   Download

MIT

The Requires

 

array terminal table text unicode ascii