-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.php
More file actions
86 lines (66 loc) · 2.12 KB
/
example.php
File metadata and controls
86 lines (66 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
require 'vendor/autoload.php';
use GuruBob\AsciiTable;
echo<<<EOT
Simple ASCII Table Generator
============================
Features
--------
* Create tables suitable for CLI output quickly
* No external dependencies
View/run example.php for examples. This file is the output of that script:
```
EOT;
$sampleData = [
['Bob Brown', 'New Zealand'],
['Wolfgang Puck', 'America'],
['Winston Churchill', 'England']
];
echo "Create table via constructor:\n";
echo new AsciiTable(
['Name', 'Country'], // Headers
$sampleData
// Optional format not specified (could be box or ascii)
);
echo "\nCreate table via OO interfaces:\n";
$table = new AsciiTable();
$table->headers(['Sales Agent', 'Travelling To']);
$table->rows($sampleData);
echo $table;
echo "\nOutput same table with different headers (reusing defined table):\n";
echo $table->headers(['Favourite Person', 'County Of Residence']);
echo "\nASCII borders instead of box:\n";
echo $table->copy()->format('ascii');
echo "Note: Made a copy() so that the following header would retain box format.\n";
echo "\nTable with no headers:\n";
echo $table->headers(null);
echo "\nCreate by chaining setters and adding individual rows:\n";
echo (new AsciiTable(['Product', 'Price']))
->addRow(['Apples', '$1.29'])
->addRow(['Bananas', '$1.69'])
->addRow(['Cherries', '$2.99'])
->format('doublebox');
echo "\nCreate by passing a collection (an array of arrays) as the first parameter:\n";
$data = [
[
'name' => 'Bob Brown',
'language' => 'English',
'timezone' => 'Pacific/Auckland'
],[
'name' => 'Roberto Collazo',
'language' => 'Spanish',
'timezone' => 'America/Mexico_City'
],[
'name' => 'Naya Yasotaro',
'language' => 'Japanese',
'timezone' => 'Asia/Tokyo'
],
];
$table = new AsciiTable($data);
echo $table;
echo "\nExclude the name column (via except()):\n";
echo $table->except('name');
echo "\nOnly show the name and timezone column (via only()):\n";
echo $table->only(['name', 'timezone']);
echo "\nNote: Use of only() and except() are mutually exclusive - setting one will unset the other\n";
echo "\n```\n";