PHP code example of malios / php-to-ascii-table
1. Go to this page and download the library: Download malios/php-to-ascii-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/ */
malios / php-to-ascii-table example snippets
$builder = new \AsciiTable\Builder();
$builder->addRows([
[
'Order No' => 'A0001',
'Product Name' => 'Intel CPU',
'Price' => 700.00,
'Quantity' => 1
],
[
'Order No' => 'A0002',
'Product Name' => 'Hard disk 10TB',
'Price' => 500.00,
'Quantity' => 2
],
[
'Order No' => 'A0003',
'Product Name' => 'Dell Laptop',
'Price' => 11600.00,
'Quantity' => 8
],
[
'Order No' => 'A0004',
'Product Name' => 'Intel CPU',
'Price' => 5200.00,
'Quantity' => 3
]
]);
$builder->addRow([
'Order No' => 'A0005',
'Product Name' => 'A4Tech Mouse',
'Price' => 100.00,
'Quantity' => 10
]);
$builder->setTitle('Product List');
echo $builder->renderTable();
// Show only some fields
$builder->showColumns(['Order No', 'Product Name', 'Quantity']);
echo $builder->renderTable();
class Person implements \JsonSerializable
{
private $name;
private $age;
public function __construct(string $name, int $age) {
$this->name = $name;
$this->age = $age;
}
public function jsonSerialize()
{
return [
'name' => $this->name,
'age' => $this->age
];
}
}
$builder = new \AsciiTable\Builder();
$builder->addRow(new Person('John', 25));
$builder->addRow(new Person('Bill', 30));
echo $builder->renderTable();