Skip to content

samadfcibd/ArrayConversion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArrayConversion

PHP Library for converting associative arrays as html table, XML, JSON, CSV. Also add, remove or edit column can be possible.

Inspired by yajra/laravel-datatables

Installation

Install the library by composer with following command:

composer install samad/array-conversion

Documentation

An associative/ multidimensional array or object can be manipulate with this script. You can convert the array/ object to HTML table, CSV file, JSON or XML data.

Suppose, you have an array as like following:

$data = [
            [
                'name' => 'Abdus Samad',
                'email' => '[email protected]'
            ],
            [
                'name' => 'Ibrahim Ahad',
                'email' => '[email protected]'
            ]
        ];

now, you can convert this $data as HTML table

$toTableInitiate = new ArrayConversion($data);
$toTableInitiate->toTable()

also, this $data can be converted into following formats:

  • CSV file toCSV()
  • JSON format toJson()
  • XML format toXml()

Add, Edit or Remove column

You can add an extra column by using closure. As like Action to each single array of $data

$addColumnToTable = new ArrayConversion($data);

$addColumnToTable->addColumn('Action', function ($data) {
    return '<button class="btn btn-success btn-xs">Action</button>';
})->toTable();

or you can remove single/ multiple column from each single array

$removeColumnFromTable = new ArrayConversion($data);

$removeColumnFromTable->removeColumn('email', 'name')
                      ->toTable();

also, you can edit column from each single array

$editColumn = new ArrayConversion($data);
$editColumn->editColumn('email', function ($data) {
    return 'Email: ' . $data['email'];
})->toTable();

After installation this library, you will see a file index.php with details example.

License

The MIT License (MIT). Please see License File for more information.

About

PHP Library for converting associative arrays as html table, XML, JSON, CSV. Also add, remove or edit column can be possible.

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages