PHP code example of dekor / php-array-table
1. Go to this page and download the library: Download dekor/php-array-table library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dekor / php-array-table example snippets
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();
use dekor\ArrayToTextTable;
use dekor\formatters\AlignFormatter;
$data = [
[
'left' => 2,
'center' => 'Dummy one',
'right' => 14.33,
],
[
'left' => 3,
'center' => 'Another great day for a great inventers!',
'right' => 1,
],
];
$builder = new ArrayToTextTable($data);
$builder->applyFormatter(new AlignFormatter(['center' => 'center', 'right' => 'right']));
echo $builder->render();
use dekor\ArrayToTextTable;
use dekor\formatters\SprintfFormatter;
$data = [
[
'left' => 1,
'right' => 2.89,
]
];
$builder = new ArrayToTextTable($data);
$builder->applyFormatter(new SprintfFormatter(['left' => '%01.3f', 'right' => '%03.3f']));
echo $builder->render();
use dekor\ArrayToTextTable;
use dekor\formatters\ColorFormatter;
$data = [
['test' => 1],
['test' => -1],
];
$builder = new ArrayToTextTable($data);
$builder->applyFormatter(new ColorFormatter(['test' => fn ($value) => $value > 0 ? 'Red' : 'Green']));
echo $builder->render() . PHP_EOL;