8ctopus/array-to-table

php array to bootstrap 5 table

0.2.0 2023-12-28 12:09 UTC

This package is auto-updated.

Last update: 2024-04-28 12:45:46 UTC


README

packagist downloads min php version license tests code coverage badge lines of code

Convert php array to Twitter bootstrap 5 table.

install and demo

composer require 8ctopus/array-to-table
<?php

declare(strict_types=1);

use Oct8pus\ArrayToTable\ArrayToTable;

require_once __DIR__ . '/vendor/autoload.php';

$data = [
    [
        'id' => 1,
        'firstName' => 'John',
        'transactionId' => 'A1-2019',
        'refunded' => 0,
        'purchaseDate' => '2019-12-01 00:00:00',
        'expiryDate' => '2020-12-01 00:00:00',
    ], [
        'id' => 2,
        'firstName' => 'Mark',
        'transactionId' => 'A1-2020',
        'refunded' => 0,
        'purchaseDate' => '2020-12-05 00:00:00',
        'expiryDate' => '2021-12-05 00:00:00',
    ], [
        'id' => 3,
        'firstName' => 'Joe',
        'transactionId' => 'A1-2022',
        'refunded' => 1,
        'purchaseDate' => '2022-12-05 00:00:00',
        'expiryDate' => '2023-12-05 00:00:00',
    ],
];

echo (new ArrayToTable($data))
    ->render();
id firstName transactionId refunded purchaseDate expiryDate
1 John A1-2019 0 2019-12-01 00:00:00 2020-12-01 00:00:00
2 Mark A1-2020 0 2020-12-05 00:00:00 2021-12-05 00:00:00
3 Joe A1-2022 1 2022-12-05 00:00:00 2023-12-05 00:00:00

You can also check the example demo.php.

tests

composer test

clean code

composer fix(-risky)