How to convert PHP array to ascii (console) table

I’ve get an interesting task on my job — make a table pretty-print in console. I’ve googled it by request like php associative array to text table, but didn’t find anything which is good for me. So I’ve developed a package on github and put it to composer so you’re able to use if in your projects.

Assuming, I’ve written a PHP-class, which allows to transform associative arrays to cool ASCII tables. I’d want to support this package in the future with adding some cool features like color print in console, printing formats, etc.

The package is simple in use:

<?php

use dekor\ArrayToTextTable;

$data = [
    [
        'id' => 1,
        'name' => 'Denis Koronets',
        'role' => 'php developer',
    ],
    [
        'id' => 2,
        'name' => 'Maxim Ambroskin',
        'role' => 'java developer',
    ],
    [
        'id' => 3,
        'name' => 'Andrew Sikorsky',
        'role' => 'php developer',
    ]
];

echo (new ArrayToTextTable($data))->render();

Will print the next output:

+----+-----------------+----------------+
| id | name            | role           |
+----+-----------------+----------------+
| 1  | Denis Koronets  | php developer  |
| 2  | Maxim Ambroskin | java developer |
| 3  | Andrew Sikorsky | php developer  |
+----+-----------------+----------------+

Github: https://github.com/deniskoronets/php-array-table

Packagist: https://packagist.org/packages/dekor/php-array-table