1. Go to this page and download the library: Download apphp/pretty-print 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/ */
apphp / pretty-print example snippets
use function Apphp\PrettyPrint\pprint;
use function Apphp\PrettyPrint\pp;
use function Apphp\PrettyPrint\ppd;
use function Apphp\PrettyPrint\{pprint, pp, ppd, pdiff, pcompare};
$matrix = [
[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],
];
// Single row (1-based)
pprint($matrix, rowsOnly: 2);
// Sparse rows and columns: rows 1,2,3,5,6 and cols 1,2,6,9,10
pprint($matrix, rowsOnly: '1-2,3,5-6', colsOnly: '1-2,6,9-10');
// Works the same for 3D tensors (applied per 2D slice)
pprint($tensor3d, rowsOnly: '2-3', colsOnly: '1,3-4');
$matrix = [
[1, 'x', 2.5, '4'],
[3, 'y', 4.5, 6],
['n/a', 'z', 1.0, null],
];
pprint($matrix, colsSummary: true);
// Adds a final summary row with sums per visible column.
// Only int/float values are -totals---)
pprint($matrix, colsSummary: true, colsSummaryLabel: '===sum===');
// Add per-row summary as an extra trailing column
pprint($matrix, rowsSummary: true);
// Customize the row-summary header label shown in the first row
pprint($matrix, rowsSummary: true, rowsSummaryLabel: '===rows===');
// No newline at the end (like Python's end="")
pprint('Same line', end: '');
// Added newline at the end after printing
pprint('Add line');
pprint('Add line', end: "\n");
// Added addedional 2 newlines at the end after printing
pprint('Add 2 lines', end: "\n\n");
// Add a prefix at the start of the printed string
pprint('Tabbed', start: "\t");
// Combine with end to avoid newline
pprint('Prompted', start: '>>> ', end: '');
// Custom separator between multiple values (default is a single space " ")
pprint('A', 'B', 'C', sep: ', ', end: '');
// A, B, C
// Separator can also be provided via trailing options array
pprint('X', 'Y', sep: "\n", end: '']);
// X
// Y