PHPackages                             jspit/tablearray - 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. jspit/tablearray

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

jspit/tablearray
================

PHP library for arrays with tableslike structure

v2.6.1(4y ago)2671MITPHPPHP &gt;=7.0

Since Jan 19Pushed 4y ago2 watchersCompare

[ Source](https://github.com/jspit-de/TableArray)[ Packagist](https://packagist.org/packages/jspit/tablearray)[ RSS](/packages/jspit-tablearray/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

TableArray
==========

[](#tablearray)

PHP library for arrays with tableslike structure (V2.6.1)

### Features

[](#features)

- Create from Array, JSON-String, CSV-String, Iterator or XML
- Methods for column selection, row filtering and sorting
- One file, no external requirements

### Installation &amp; loading

[](#installation--loading)

Manually:

- Code -&gt; Download ZIP TableArray-master.zip
- Extract zip to a new Folder

Of course, you can also copy the TableArray source code to your editor and save it.

```
use Jspit\TableArray;
require '/Path_to_Folder/TableArray.php';

var_dump(TableArray::VERSION);  //string(5) "2.6.1"
```

Install via Composer:

run

```
composer require jspit/tablearray
```

```
use Jspit\TableArray;
require '/Path_to_Composer_vendor_Folder/vendor/autoload.php';

var_dump(TableArray::VERSION);  //string(5) "2.6.1"
```

### Usage

[](#usage)

#### Simple example 1

[](#simple-example-1)

```
$data = [
  ['id' => 1, 'val' => 23.333333333],
  ['id' => 2, 'val' => 13.7777777777],
];
$newData = TableArray::create($data)
  ->select('id, FORMAT("%6.2f",val) as rval')
  ->orderBy('val ASC')
  ->fetchAll();

$expected = [
  ['id' => 2, 'rval' => " 13.78"],
  ['id' => 1, 'rval' => " 23.33"],
];
var_dump($newData == $expected); //bool(true)
```

#### Simple example 2

[](#simple-example-2)

```
$data = [
  ['name' => 'A1', 'likes' => 3],
  ['name' => 'A12', 'likes' => 6],
  ['name' => 'A2','likes' => 14],
  ['name' => 'A14','likes' => 7],
];

$newData = TableArray::create($data)
  ->select('name AS class, likes')
  ->orderBy('name ASC NATURAL')
  ->fetchAll();

$expected = [
  ['class' => 'A1', 'likes' => 3],
  ['class' => 'A2','likes' => 14],
  ['class' => 'A12', 'likes' => 6],
  ['class' => 'A14','likes' => 7],
];
var_dump($newData === $expected); //bool(true)
```

#### Pivot Group example

[](#pivot-group-example)

```
$data = [
  ['group' => 1, 'type' => 'A', 'value' => 'AA'],
  ['group' => 2, 'type' => 'A', 'value' => 'BB'],
  ['group' => 1, 'type' => 'B', 'value' => 5],
  ['group' => 2, 'type' => 'B', 'value' => 7],
];
$newData = TableArray::create($data)
  ->pivot('group','value','type')
  ->fetchAll();

$expected = [
  1 => ['group' => 1, 'value.A' => "AA", 'value.B' => 5 ],
  2 => ['group' => 2, 'value.A' => "BB", 'value.B' => 7 ],
];
```

#### CSV Import example

[](#csv-import-example)

```
TableArray::setCsvDefaultOptions([
  'delimiter'=>',',
  'title => true',  //use first row as keys
]);
$data = TableArray::createFromCsvFile('file.csv')
  ->fetchAll()
;
```

#### Example filterGroupAggregate

[](#example-filtergroupaggregate)

```
$data = [
  ['id' => "1",'group' => 1, 'value' => 2, 'value2' => 3],
  ['id' => "2",'group' => 2, 'value' => 4, 'value2' => 7],
  ['id' => "3",'group' => 1, 'value' => 1, 'value2' => 2],
  ['id' => "4",'group' => 2, 'value' => 6, 'value2' => 8],
];

$newData = TableArray::create($data)
  ->filterGroupAggregate(['value' => 'MAX', 'value2' => 'AVG'],['group'])
  ->orderBy('value2 DESC')
  ->fetchAll();

$expected = [
  ['id' => "4",'group' => 2, 'value' => 6, 'value2' => 7.5],
  ['id' => "1",'group' => 1, 'value' => 2, 'value2' => 2.5],
];
var_dump($newData === $expected);  //bool(true)
```

#### Data input methods

[](#data-input-methods)

- new TableArray ($dataArray,\[$keyPathToData\])
- create ($dataArray,\[$keyPathToData\])
- createFromJson ($jsonStr,\[$keyPathToData\])
- createFromXml ($xml, \[$strXPath\])
- createFromOneDimArray ($dataArray,\[$delimiter\])
- createFromString ($inputString, \[$regExValues,\[$regExSplitLines\]\])
- createFromGroupedArray($input, $keyArray)
- createFromCsvFile(\[$file\])

#### General Working methods

[](#general-working-methods)

- [select](#select)
- [orderBy](#orderBy)
- innerJoinOn
- leftJoinOn
- flatten
- merge
- pivot
- offset
- limit
- transpose
- collectChilds

#### Filter methods

[](#filter-methods)

- filter
- filterEqual
- filterLikeAll
- filterLikeIn
- filterUnique
- filterGroupAggregate

#### Methods to fetch the data

[](#methods-to-fetch-the-data)

- fetchAll
- fetchAllObj
- fetchAllAsJson
- fetchAllAsCSV
- fetchKeyValue
- fetchColumn
- fetchColumnUnique
- fetchGroup
- fetchRow
- fetchRaw
- fetchLimit
- fetchLimitFromEnd

#### Other methods

[](#other-methods)

- addFlatKeys
- addKeys
- fieldAsKey
- firstRowToKey
- addSqlFunction
- addSqlFunctionFromArray
- getSqlFunction
- fieldNameRaw
- setOption
- getOption
- setCsvDefaultOptions($options)
- check($data)
- unGroup($array, $keys)
- count
- toClass
- print($comment,$limit)

#### Internal functions may be used by select and orderBy

[](#internal-functions-may-be-used-by-select-and-orderby)

- ABS(fieldName)
- UPPER(fieldName)
- FIRSTUPPER(fieldName)
- LOWER(fieldName)
- TRIM(fieldName\[,'character\_mask'\])
- FORMAT('format',fieldName\[,fieldName\])
- SCALE(fieldName,'factor'\[,'add'\[,'format'\]\])
- DATEFORMAT('dateFormat',fieldName)
- REPLACE('search','replace',fieldName)
- SUBSTR(fieldName,'start'\[,'length'\])
- LIKE(fieldName,'likePattern')
- INTVAL(fieldName,'basis')
- FLOATVAL(fieldName,\['dec\_point', 'thousands\_sep'\])
- NULLCOUNT(fieldName\[,fieldName,..\])
- CONCAT(fieldName\[,fieldName,..\])
- IMPLODE(arrayFieldName,\['delimiter'\])
- SPLIT(fieldName\[,'delimiter'\[,'number'\]\])

#### Interface

[](#interface)

- Iterator
- JsonSerializable

#### Class Methods

[](#class-methods)

##### select

[](#select)

Select rows for a fetch -&gt;select('field1, field2,..') -&gt;select('field1 as newName,..') -&gt;select('fct(field1) as newName,..)

```
$data =[
  ['id' => 1, 'article' => "pc1", 'price' => 1231.0],
  ['id' => 1, 'article' => "pc2", 'price' => 471.5],
];

$newData = TableArray::create($data)
  ->select("article as Name, FORMAT('%.2f€',price) as Euro")
  ->fetchAll()
;
/* Result $newData
[
  ['Name' => "pc1", 'Euro' => "1231.00€"],
  ['Name' => "pc2", 'Euro' => "471.50€",
]
*/
```

##### orderBy

[](#orderby)

Sorts the array by one or more columns in ascending or descending order.

-&gt;orderBy('field1 \[ASC|DESC\]\[NATURAL\], \[field2..\]')

-&gt;orderBy('fct(field1,\[params\]),\[field|function..\])

### Documentation

[](#documentation)

### Examples and Test

[](#examples-and-test)

### Requirements

[](#requirements)

- PHP 7.x

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

1579d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/22937dc20397722cf671d80f783747b9633935652b62a79543383afff3fd93c2?d=identicon)[jspit](/maintainers/jspit)

---

Top Contributors

[![jspit-de](https://avatars.githubusercontent.com/u/10461360?v=4)](https://github.com/jspit-de "jspit-de (72 commits)")

### Embed Badge

![Health badge](/badges/jspit-tablearray/health.svg)

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

###  Alternatives

[firefly-iii/data-importer

Firefly III Data Import Tool.

7545.8k](/packages/firefly-iii-data-importer)[appsero/client

Appsero Client

25431.7k9](/packages/appsero-client)[parfaitementweb/filament-country-field

Country dropdown with ISO 3166 options values

19155.0k1](/packages/parfaitementweb-filament-country-field)[mandango/mondator

Easy and flexible class generator for PHP

1917.9k3](/packages/mandango-mondator)[marvinlabs/laravel-html-font-awesome

A fluent html builder for Font Awesome icons

151.7k](/packages/marvinlabs-laravel-html-font-awesome)

PHPackages © 2026

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