PHPackages                             simbiat/array2table - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. simbiat/array2table

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

simbiat/array2table
===================

Library to convert arrays to table.

2.0.13+20240529(1y ago)234[8 issues](https://github.com/Simbiat/array2table/issues)AGPL-3.0-or-laterPHPPHP ^8.3

Since Oct 26Pushed 2w ago1 watchersCompare

[ Source](https://github.com/Simbiat/array2table)[ Packagist](https://packagist.org/packages/simbiat/array2table)[ Docs](https://github.com/Simbiat/array2table)[ RSS](/packages/simbiat-array2table/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (10)Dependencies (1)Versions (18)Used By (0)

Array To Table converter
========================

[](#array-to-table-converter)

Split data types into separate classes As result you can generate respective HTML elements from the respective classes directly, if required Sanitize flag is now per type Counts are now static in each respective class, and will increase with each successful generation Removed classes from the elements, since IDs will are enough (can be matched by wildcards) $dateformat moved to Types\\Date class as $format and is now a public static string Date/time formatting with SandClock is done only if field is not editable and $sand\_clock attribute of the respective class is true Seconds now support all the SandClock attributes for seconds (as public static attributes) Seconds also now have a pattern for input field Bytes and Seconds now expect the CuteBytes and SandClock libraries to be present. If you do not want to use them - update respective flags in Type class URL now supports whitespace setting for PrettyURL. URLs are always sanitized Email and URL will throw an error if not a valid email/URL and not an empty string is provided, instead of creating a `span`

This library is used for creating HTML tables using data provided to it in an array. When will you want to use it? I believe, there are 2 use-cases:

- You are presenting a lot of homogeneous data from your database
- You are creating some relatively simple form (like user settings) and do not want that much customization for it

Yes, this library can be used for creating forms, that you will be able to process further, once they are submitted. And the unique feature here is that form elements will not be just text-fields: library supports checkboxes, date/time fields, colors, files, .etc. Each element will be created with the minimum required attributes, with automatically generated IDs and classes (for CSS customization or JavaScript interactivity, if required).

Note, that it is discouraged to use this library, if you already have a template engine (like Twig) in your project, since it will probably be more efficient and secure, especially when dealing with HTML inside the fields. Use of this library may make sense if you do not have anything generating actual web pages, and you want to generate some sort of report based on the output of a function.

- [Data Types](#data-types)
- [Settings](#settings)

How to use
==========

[](#how-to-use)

The best way to understand what you will be getting is a live example, so check out `sample.html` somewhere near this README. There you will find 3 tables, that were generated using following code:

```
echo (new \Simbiat\ArrayToTable\Generator)->setIdPrefix('sem_edit')->setCaption('Semantic, editable')->setFooter(['#func_sum','',''])->setCheckbox(true)->setChecked(true)->setEditable(true)->setTypes(['number','string',['text','password','tel','date', 'time', 'datetime', 'seconds', 'bytes', 'price', 'checkbox', 'email', 'url', 'html', 'img', 'color']])->generate(
    [
            ['Points'=>'1','Field'=>'Login','Value'=>'Simbiat'],
            ['1','Password','Simbiat'],
            ['1','Telephone','+74991752327'],
            ['1','Date of birth','12-05-1989'],
            ['1','Current time',time(),],
            ['1','Last login',time(),],
            ['1','Seconds','123456',],
            ['1','Image size','1234567',],
            ['1','Salary','123456',],
            ['1','Are you a robot?','No',],
            ['1','Email','support@simbiat.eu',],
            ['1','Website','https://www.simbiat.eu',],
            ['1','Signature','Awesome website'],
            ['1','Avatar','https://media.kitsu.io/users/avatars/41172/large.jpg'],
            ['1','Favorite color','006E72'],
    ]
);

echo (new \Simbiat\ArrayToTable\Generator)->setIdPrefix('sem_non_edit')->setCaption('Semantic, non-editable')->setFooter(['#func_sum','',''])->setCheckbox(true)->setChecked(true)->setEditable(false)->setTypes(['number','string',['text','password','tel','date', 'time', 'datetime', 'seconds', 'bytes', 'price', 'checkbox', 'email', 'url', 'html', 'img', 'color']])->generate(
    [
            ['Points'=>'1','Field'=>'Login','Value'=>'Simbiat'],
            ['1','Password','Simbiat'],
            ['1','Telephone','+74991752327'],
            ['1','Date of birth','12-05-1989'],
            ['1','Current time',time(),],
            ['1','Last login',time(),],
            ['1','Seconds','123456',],
            ['1','Image size','1234567',],
            ['1','Salary','123456',],
            ['1','Are you a robot?','No',],
            ['1','Email','support@simbiat.eu',],
            ['1','Website','https://www.simbiat.eu',],
            ['1','Signature','Awesome website'],
            ['1','Avatar','https://media.kitsu.io/users/avatars/41172/large.jpg'],
            ['1','Favorite color','006E72'],
    ]
);

echo (new \Simbiat\ArrayToTable\Generator)->setIdPrefix('non_sem_non_edit')->setCaption('Non-semantic, non-editable')->setSemantic(false)->setStyling(true)->setFooter(['#func_sum','',''])->setCheckbox(true)->setChecked(true)->setEditable(false)->setTypes(['number','string',['text','password','tel','date', 'time', 'datetime', 'seconds', 'bytes', 'price', 'checkbox', 'email', 'url', 'html', 'img', 'color']])->generate(
    [
            ['Points'=>'1','Field'=>'Login','Value'=>'Simbiat'],
            ['1','Password','Simbiat'],
            ['1','Telephone','+74991752327'],
            ['1','Date of birth','12-05-1989'],
            ['1','Current time',time(),],
            ['1','Last login',time(),],
            ['1','Seconds','123456',],
            ['1','Image size','1234567',],
            ['1','Salary','123456',],
            ['1','Are you a robot?','No',],
            ['1','Email','support@simbiat.eu',],
            ['1','Website','https://www.simbiat.eu',],
            ['1','Signature','Awesome website'],
            ['1','Avatar','https://media.kitsu.io/users/avatars/41172/large.jpg'],
            ['1','Favorite color','006E72'],
    ]
);
```

Here's what the code does:

1. Create new object with `(new \Simbiat\array2table)`. Obviously load the library before that.
2. Optionally set a `prefix` for elements' IDs and Classes with `setIdPrefix('prefix')`. Very useful, in case you will have multiple tables like that on one page, like `sample.html` does.
3. Optionally set `caption` for the table with `setCaption('caption')`. If this is set a `` will be added to the table if it's semantic or respective `` if it's not. Basically, this is a name of the table.
4. In case of non-semantic tables we have `setSemantic(false)`. This forces use of `` elements instead if regular (semantic) table elements (table, td, tr, th, etc.). When creating actual tables, it is recommended to use semantic approach (thus default is `true`), but in some cases you may want to have ``.
5. Optionally enable basic styling for `` elements for non-semantic approach with `setStyling(true)`. This will add inline `style` attributes to make non-semantic table look more like its semantic counterpart. Styling is based on WebKit stylesheet at the time of writing.
6. Optionally set `footer` with `setFooter(['','',''])`. If this is set `` will be added to the table if it's semantic or respective `` if it's not. This is a row that will appear at the bottom of the table. If set, its length will be checked against the number of columns the data have and if different - throw an exception. `footer` can be used to repeate `header` with `setFooterHeader(true)`. In case of `sample.html` we also use `#func_sum` to calculate total (sum) of the values in respective column.
7. Optionally set currency for `currency` values with `setCurrencyCode('USD ')`. Adding space at the end of the value will place the currency before the values. Default is `''`, that empty string.
8. Optionally set `precision` for `currency` values with `setCurrencyPrecision(2)`. This determines number of digits after dot. Default is `2`.
9. Optionally set initial format used by `currency` values with `setCurrencyFraction(true)`. If `true` converter will expect values to be "fractions", like cents for USD, thus will consider the last 2 digits of a value as cents and put them after the dot. If `false` - will expect a float and/or convert to it.
10. Optionally add checkbox for each lie with `setCheckbox(true)`. This may be useful when you want to allow user to remove some entries, for example. Set is as checked with `setChecked(true)`.
11. Optionally make the values of the table editable with `setEditable(true)`. This will replace values with appropriate `` elements.
12. Optionally adjust size of `` elements with `setTextareaSetting('cols', '20')->setTextareaSetting('rows', '5')`.
13. Set values types with `setTypes(['number','string',['text','password','tel','date', 'time', 'datetime', 'seconds', 'bytes', 'price', 'checkbox', 'email', 'url', 'html', 'img', 'color']])`. In the example 2 first columns (array elements) have one type for all values in them. Both of them are not, actually, a supported type from the list, thus they will turn into regular `` elements. The 3rd column uses an array of types with separate type for each row. It's not required to have different types for each: this is done only for the sample purpose to showcase all of currently supported types. It is required to have the same number of types as you have actual data rows or an exception will be thrown.
14. Actually generate the table with

```
generate(
    [
            ['Points'=>'1','Field'=>'Login','Value'=>'Simbiat'],
            ['1','Password','Simbiat'],
            ['1','Telephone','+74991752327'],
            ['1','Date of birth','12-05-1989'],
            ['1','Current time',time(),],
            ['1','Last login',time(),],
            ['1','Seconds','123456',],
            ['1','Image size','1234567',],
            ['1','Salary','123456',],
            ['1','Are you a robot?','No',],
            ['1','Email','support@simbiat.eu',],
            ['1','Website','https://www.simbiat.eu',],
            ['1','Signature','Awesome website'],
            ['1','Avatar','https://media.kitsu.io/users/avatars/41172/large.jpg'],
            ['1','Favorite color','006E72'],
    ]
```

Each "inner" array in "outer" array represents a row, while each element in "inner" arrays - respective column. In sample 1st row is using an associative array for optional header value (creates ``). Alternatively `setHeader([])` can be used to the same effect.

Data types
==========

[](#data-types)

  Type Input element Description   date `` If `Simbiat\SandClock` library is registered will attempt to show date according to its logic, otherwise will keep the value as is. If editable, will enforce certain format for the value, when sending the form.   time `` If `Simbiat\SandClock` library is registered will attempt to show time according to its logic, otherwise will keep the value as is. If editable, will enforce certain format for the value, when sending the form.   datetime `` If `Simbiat\SandClock` library is registered will attempt to show date and time according to its logic, otherwise will keep the value as is. If editable, will enforce certain format for the value, when sending the form.   seconds `` If `Simbiat\SandClock` library is registered will attempt to convert seconds to time length according to its logic, otherwise will keep the value as is. If editable, will attempt to force decimal virtual keyboard, depending on browser support   bytes `` If `Simbiat\CuteBytes` library is registered will attempt to convert bytes to other sizes according to its logic, otherwise will keep the value as is. If editable, will attempt to force decimal virtual keyboard, depending on browser support   price `` Converts provided value into a float with an optional currency sign representing an amount of that currency. If editable, will attempt to force decimal virtual keyboard, depending on browser support   checkbox `` Converts value to a checkbox. Values like `yes`, `no`, `on`, `off` will be converted to `true` or `false`, while for others `boolval` will be used for the same. If result is `true` - checkbox will be ticked (`checked` attribute added). If not editable, `disabled` attribute will be added.   email `` Returns `` element using `mailto:` URI if validates as actual email. If not - will be treated as regular text in ``. If editable and browser implements input type `email` - will validate the value when sending form.   url `` Returns `` element if validates as actual email. If not - will be treated as regular text in ``. If editable and browser implements input type `url` - will validate the value when sending form. If `Simbiat\PrettyURL` is registered, will sanitize the value before processing.   html `value` Treats string same as `textarea`, but sanitizes the value before processing.   textarea `value` Shows text as ``. If editable, shows appropriate textarea. \*\*Be extremely careful with the text you allow users to input here, because it can be easily exploited! Use some kind of sanitization process when submitting form!\*\*   text `` Returns regular text or respective `` element.   tel `` Same as `text`, but will enforce specific virtual keyboard if browser supports it.   password `` Same as `text`, but will clear the value (always) and apply pattern. Pattern is stored as `public static $PasswordPattern` and can be changed if you want to, but it's advised against in order to comply with the minimum complexity recommendations.   img `` If not editable, returns `` element with source equal to value provided. Otherwise, acts same as `file`.   file `` Provides field for file upload, if editable (if not, the element will be disabled). Use `setMultipleFiles(true)` to allow upload of multiple files.   color `` Returns color picker if supported by browser. No need to send `#` when providing data, since it will be added automatically. Settings
========

[](#settings)

  Setter function Description   `setSemantic(bool $semantic = true)` Generate `` (semantic) if true or `` (non-semantic) if false.   `setStyling(bool $styling = false)` Force basic inline styling for `` variant. Custom styling is recommended.   `setCheckbox(bool $checkbox = false)` Generate with first column being a checkbox with unique ID if true. Works for multi-arrays only.   `setChecked(bool $checked = false)` Generate with first column checkbox checked if true.   `setSanitize(bool $sanitize) = true` Attempt to strip tags and encode HTML entities, unless `html` data type.   `setEditable(bool $editable = false)` Flag to allow edit of the editable fields.   `setCaption(string $caption = '')` Optional caption (name) for tables.   `setHeader(array $header = [])` Optional header for tables. Expects array with same length as number of columns in data provided. Alternatively will attempt to use keys from first row, if it's an associative array.   `setRepeatHeader(int $repeat_header = 0)` If value is not 0, will repeat header every X number of lines, where X is the value set by this setter. Recommended for large tables.   `setFooter(array $footer = [])` Optional footer for tables. Expects array with same length as number of columns in data provided. Supports functions for columns with singular data type: `'#func_sum'` (sum of all values in column), `'#func_avg'` (average of all values in column), `'#func_min'` (lowest value in column), `'#func_max'` (maximum value in column)   `setFooterHeader(bool $footer_header = false)` Use header text in footer.   `setColGroup(array $colgroup = [])` Setter for optional `colgroup` definition, which allows grouping of columns through HTML classes. Expect array like `[['span'=>2,'class'=>'col_class','style'=>'col_style'],[...],...,[...]]`. `'span'` expect a numeric value identifying number of columns in a group. `'class'` expects a class that will be additionally applied to the group. `'style'` expects a CSS style string that will be additionally applied to group.   `setTypes(array $types = [])` Optional list of types to be applied to columns and rows. Expects an array in format as described in \[How to use\](#how-to-use).   `setIdPrefix(string $id_prefix = 'simbiat')` Optional prefix for elements' IDs and some of the classes.   `setMultipleFiles(bool $multiple_files = false)` Option to allow multiple files upload for file fields.   `setDateFormat(string $dateformat = 'Y-m-d')` Date format to use with `Simbiat\SandClock` library for `date` type.   `setTimeFormat(string $time_format = 'H:i:s')` Time format to use with `Simbiat\SandClock` library for `time` type.   `setDateTimeFormat(string $datetime_format = '')` Date and time format to use with `Simbiat\SandClock` library for `date` type. If empty will combine date format and time format set by respective setters as `date time`.   `setLanguage(string $language = 'en')` Language to use with `Simbiat\SandClock` library for `seconds` type.   `setBytesSettings(int $power = 1000, int $decimals = 2, string $dec_point = '.', string $thousands_sep = ',', int $numbers = 0, bool $bits = false)` Customization for bytes styling using [CuteBytes](https://github.com/Simbiat/cute-bytes) class.   `setTextareaSetting(int $rows = 20, int $cols = 20, int $minlength = 0, int $maxlength = 0)` Customization options for `textarea` elements.   `setCurrencySettings(string $code = '', int $precision = 2, bool $fraction = true)` Currency settings for `price` type.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance48

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~104 days

Recently: every ~149 days

Total

17

Last Release

717d ago

Major Versions

1.2.0+20210129 → 2.0.0+202103102021-03-10

PHP version history (4 changes)1.0.0+20191026PHP ^7.0.7

1.1.0+20200905PHP ^7.4

2.0.0+20210310PHP ^8

2.0.10+20240407PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6022665?v=4)[Dmitrii Kustov](/maintainers/Simbiat)[@Simbiat](https://github.com/Simbiat)

---

Top Contributors

[![Simbiat](https://avatars.githubusercontent.com/u/6022665?v=4)](https://github.com/Simbiat "Simbiat (1 commits)")

---

Tags

phparrayconvertertable

### Embed Badge

![Health badge](/badges/simbiat-array2table/health.svg)

```
[![Health](https://phpackages.com/badges/simbiat-array2table/health.svg)](https://phpackages.com/packages/simbiat-array2table)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
