Skip to content

Commit e12cd8a

Browse files
1.7
1 parent bae5e38 commit e12cd8a

File tree

3 files changed

+125
-116
lines changed

3 files changed

+125
-116
lines changed

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ What it does? Filter, order, renaming column, grouping, validating, amongst many
77

88
- [x] it works with PHP arrays. PHP arrays allows hierarchy structures using indexed and/or associative values.
99
- [x] It is aimed at speed.
10-
- [x] It is minimalist, using the minimum of dependencies and only 1 PHP class. Do you hate when a simple library adds a whole framework as difference? Well, not here.
10+
- [x] It is minimalist, using the minimum of dependencies and only 1 PHP class. Do you hate when a simple library adds a whole framework as dependency? Well, not here.
1111
- [x] It works using fluent/nested notations.
1212
- [x] Every method is documented using PhpDoc.
1313

@@ -38,7 +38,7 @@ What it does? Filter, order, renaming column, grouping, validating, amongst many
3838
* [flat](#flat)
3939
* [group](#group)
4040
* [example](#example)
41-
* [indexToColumn](#indextocolumn)
41+
* [indexToCol](#indextocol)
4242
* [join](#join)
4343
* [last](#last)
4444
* [map](#map)
@@ -63,7 +63,7 @@ What it does? Filter, order, renaming column, grouping, validating, amongst many
6363
* [makeRequestArrayByExample](#makerequestarraybyexample)
6464
* [versions](#versions)
6565
* [License](#license)
66-
<!-- TOC -->
66+
<!-- TOC -->
6767

6868
## Basic examples
6969

@@ -248,10 +248,13 @@ $this->flat(); // [['a'=>1,'b'=>2]] => ['a'=>1,'b'=>2]
248248
```
249249
* **return value** $this
250250
### group
251-
It groups one column and return its column grouped and values aggregated
251+
It groups one column and return its column grouped and values aggregated.
252+
> The grouped value is used as the new index key.
253+
252254
**Example:**
253255
```php
254-
$this->group('type',['amount'=>'sum','price'=>'sum']);
256+
$this->group('type',['amount'=>'sum','price'=>'sum']); // ['type1'=>['amount'=>20,'price'=>30]]
257+
$this->group('type',['am'=>'sum','pri'=>'sum','grp'=>'group'],false); // [['am'=>20,'pri'=>30,'grp'=>'type1']]
255258
$this->group('type',['newcol'=>'sum(amount)','price'=>'sum(price)']);
256259
```
257260
* **parameter** mixed $column the column to group.
@@ -264,8 +267,10 @@ $this->group('type',['newcol'=>'sum(amount)','price'=>'sum(price)']);
264267
<b>max</b>: Maximum
265268
<b>sum</b>: Sum
266269
<b>first</b>: First
267-
<b>last</b>: last
268-
270+
<b>last</b>: last
271+
<b>group</b>: The grouped value
272+
* **parameter** bool $useGroupAsIndex (def true), if true, then the result will use the grouped value as index<br>
273+
if false, then the result will return the values as an indexed array.
269274
#### example
270275

271276
```php
@@ -298,12 +303,12 @@ $result=ArrayOne::set($array)
298303

299304
```
300305

301-
### indexToColumn
306+
### indexToCol
302307

303308
It converts the index into a field, and renumerates the array
304309
**Example:**
305310
```php
306-
$this->indexToField('colnew'); // ['a'=>['col1'=>'b','col2'=>'c']] => [['colnew'=>'a','col1'=>'b','col2'=>'c']
311+
$this->indexToCol('colnew'); // ['a'=>['col1'=>'b','col2'=>'c']] => [['colnew'=>'a','col1'=>'b','col2'=>'c']
307312
```
308313
* **parameter** mixed $newColumn the name of the new column
309314
* **return value** $this
@@ -369,6 +374,7 @@ $this->reduce(function($row,$index,$prev) { return ['col1'=>$row['col1']+$prev['
369374
A function using the syntax: function ($row,$index,$prev) where $prev
370375
is the accumulator value
371376
* **return value** $this
377+
372378
### removecol
373379
It removes a column
374380
**Example:**
@@ -477,13 +483,13 @@ class ServiceClass {
477483
// 2.1) and setting the service class using the class
478484
ValidateOne
479485
->set($array,ServiceClass:class)
480-
->validate('field'=>'fn:test')
486+
->validate('field'=>'fn:test') // or ->validate('field'=>[['fn','test']])
481487
->all();
482488
// 2.2) or you could use an instance
483489
$obj=new ServiceClass();
484490
ValidateOne
485491
->set($array,$obj)
486-
->validate('field'=>'fn:test')
492+
->validate('field'=>'fn:test') // or ->validate('field'=>[['fn','test']])
487493
->all();
488494
```
489495

@@ -577,6 +583,10 @@ $this->makeRequestArrayByExample(['a'=1,'b'=>2]); // ['a'='post','b'=>'post'];
577583

578584

579585
## versions
586+
* 1.7 2023-06-04
587+
* [new] group() allows to return the grouped value. It also allows to return the values as an indexed array
588+
* 1.6 2023-04-10
589+
* [optimization] setCurrentArray() now is only used when nav() is called or when the value is returned.
580590
* 1.5 2023-04-07
581591
* [new] filtercondition() now allow conditions as array.
582592
* 1.4 2023-04-05

0 commit comments

Comments
 (0)