phpcheck.class.tablearray.php Total: 175 Tests, 0 Errors
PHPCheck V1.59, OS: Linux, Machine: Linux localhost 3.10.0-1160.36.2.el7.x86_64 #1 SMP, PHP-Version: 7.4.29 (64 Bit), Time: 0.081 s, Memory: 16.0M (512M)
CommentLineCodeResultTest
exist versions info 22 $info $t->getClassVersion(TableArray::class);
$t->check($info, !empty($info) AND $info >= 2.6); 
[0.217 ms]
'2.6'
Ok
create Object from Array 26 $data = [
  
=> ['name' => 'Meier''likes' => 3],
  
=> ['name' => 'Lehmann''likes' => 6],
  
=> ['name' => 'Schulz','likes' => 14],
];
$TableArray = new TableArray($data);  
//or $sqlObj = TableArray::create($data);
$t->check($TableArray$TableArray instanceOf TableArray); 
[0.019 ms]
TableArray::__set_state(array( ))
Ok
create Object from Sub-Array and array Key-Path 36 $data = [
  
'id' => "xp67",
  
'result' => [
    
'total' => 8
    
'items' => [
      [
'id' => "1"'name' => "Default"],
      [
'id' => "2"'name' => "PC"]
    ],
  ],
];
$subArr TableArray::create($data,['result','items'])
  ->
fetchAll()
;
$t->checkEqual($subArr$data['result']['items']); 
[0.036 ms]
array ( 0 => array ( 'id' => '1', 'name' => 'Default', ), 1 => array ( 'id' => ' ..
Ok
create Object from Sub-Array and string Key-Path 52 $data = [
  
'id' => "xp67",
  
'result' => [
    
'total' => 8
    
'items' => [
      [
'id' => "1"'name' => "Default"],
      [
'id' => "2"'name' => "PC"]
    ],
  ],
];
$subArr TableArray::create($data,'result.items')
  ->
fetchAll()
;
$t->checkEqual($subArr$data['result']['items']); 
[0.011 ms]
array ( 0 => array ( 'id' => '1', 'name' => 'Default', ), 1 => array ( 'id' => ' ..
Ok
create from 1.dimensional Array 69 $data = ['/image/9x9.png','/image/40x1.png','/upload/40x2.png'];
//Field get the name file
$newData TableArray::createFromOneDimArray($data)
  ->
fetchAll();
$expected = [
  [
0,'/image/9x9.png'],
  [
1'/image/40x1.png'],
  [
2'/upload/40x2.png']
];
$t->checkEqual($newData,$expected); 
[0.009 ms]
array ( 0 => array ( 0 => 0, 1 => '/image/9x9.png', ), 1 => array ( 0 => 1, 1 => ..
Ok
create from 1.dimensional Array with keys 81 $data = [
  
=> 2.0,
  
=> 3.5,
];
$newData TableArray::createFromOneDimArray($data)
  ->
fetchAll();
$expected = [
  [
42.0],
  [
53.5],
];
$t->checkEqual($newData,$expected); 
[0.005 ms]
array ( 0 => array ( 0 => 4, 1 => 2.0, ), 1 => array ( 0 => 5, 1 => 3.5, ), )
Ok
createFromOneDimArray with row delimter 94 $data = [
  
'1 line1 5',
  
'2 line2 7',
];
$newData TableArray::createFromOneDimArray($data" ")
  ->
fetchAll();
$expected = [
  [
'1',"line1",'5'],
  [
'2',"line2",'7'],
];
$t->checkEqual($newData,$expected); 
[0.020 ms]
array ( 0 => array ( 0 => '1', 1 => 'line1', 2 => '5', ), 1 => array ( 0 => '2', ..
Ok
createFromOneDimArray with regEx delimter 107 $data = [
'1 08:02:12',
'2 09:00:15'
];
$regEx '/^(\d+) (\d+):(\d+):(\d+)/';
$newData TableArray::createFromOneDimArray($data,$regEx)
  ->
fetchAll()
;
$expected = [
  [
'1','08','02','12'],
  [
'2','09','00','15'],
];
$t->checkEqual($newData,$expected); 
[0.058 ms]
array ( 0 => array ( 0 => '1', 1 => '08', 2 => '02', 3 => '12', ), 1 => array ( ..
Ok
createFromString with rowDel = " " 123 $data '1 08:11:28
0 08:02:23
1 09:11:24
2 08:00:28'
;
$newData TableArray::createFromString($data,' ')
  ->
fetchAll()
;
$expected = [
  [ 
=> "1"=> "08:11:28"],
  [ 
=> "0"=> "08:02:23"],
  [ 
=> "1"=> "09:11:24"],
  [ 
=> "2"=> "08:00:28"],
];
$t->checkEqual($newData,$expected); 
[0.037 ms]
array ( 0 => array ( 0 => '1', 1 => '08:11:28', ), 1 => array ( 0 => '0', 1 => ' ..
Ok
createFromString with split , and " " 139 $coordinates "9.499819 123.920318,9.490845 123.916563,9.484644 123.922292";
$newData TableArray::createFromString($coordinates,' ','/,/')
  ->
select("FLOATVAL(0) as lat, FLOATVAL(1) as lng"
  ->
fetchAll()
;
$expected = [
  [
'lat' => 9.499819,'lng' => 123.920318],
  [
'lat' => 9.490845,'lng' => 123.916563],
  [
'lat' => 9.484644,'lng' => 123.922292]
];
$t->checkEqual($newData,$expected); 
[0.091 ms]
array ( 0 => array ( 'lat' => 9.499819, 'lng' => 123.920318, ), 1 => array ( 'la ..
Ok
createFromString with rowDel = regEx 152 $data '1 08:11:28
0 08:02:23
1 09:11:24
2 08:00:28'
;
$newData TableArray::createFromString($data,'/^(\d+) (\d+)/')
  ->
fetchAll()
;
$expected = [
  [ 
=> "1"=> "08"],
  [ 
=> "0"=> "08"],
  [ 
=> "1"=> "09"],
  [ 
=> "2"=> "08"],
];
$t->checkEqual($newData,$expected); 
[0.030 ms]
array ( 0 => array ( 0 => '1', 1 => '08', ), 1 => array ( 0 => '0', 1 => '08', ) ..
Ok
createFromString with rowDel = regEx and named groups 168 $data '1 08:11
0 08:02
2 09:15'
;
$regEx '/^(?<c>\d+) (?<hour>\d+):(?<minute>\d+)/';
$newData TableArray::createFromString($data$regEx)
  ->
fetchAll()
;
$expected = [
  [
'c' => "1"'hour' => "08"'minute' => "11"],
  [
'c' => "0"'hour' => "08"'minute' => "02"],
  [
'c' => "2"'hour' => "09"'minute' => "15"],
];
$t->checkEqual($newData,$expected); 
[0.037 ms]
array ( 0 => array ( 'c' => '1', 'hour' => '08', 'minute' => '11', ), 1 => array ..
Ok
createFromString and split columns with regEx 183 $input 'program    hall    start    end
program0    1     2020-10-02 09:30:00     2020-10-02 10:30:00
program1    2     2020-10-02 11:30:00     2020-10-02 13:30:00'
;

//2 or more blanks, s is an identifier, does not belong to the regex
$regExSplitColumn "s/  +/";

$data TableArray::createFromString($input,$regExSplitColumn)
  ->
firstRowToKey()
  ->
fetchAll()
;
$expected = [
  [
'program' => 'program0''hall' => '1''start' => '2020-10-02 09:30:00''end' => '2020-10-02 10:30:00'],
  [
'program' => 'program1''hall' => '2''start' => '2020-10-02 11:30:00''end' => '2020-10-02 13:30:00']
];
$t->checkEqual($data,$expected); 
[0.028 ms]
array ( 0 => array ( 'program' => 'program0', 'hall' => '1', 'start' => '2020-10 ..
Ok
create Object from JSON-String 202 $json '[{"name":"Meier","likes":3},{"name":"Lehmann","likes":6},{"name":"Schulz","likes":14}]';
$TableArray TableArray::createFromJson($json);
$t->check($TableArray$TableArray instanceOf TableArray); 
[0.042 ms]
TableArray::__set_state(array( ))
Ok
create Object from JSONP-String 207 $jsonP "functionCall(".$json.")";
$TableArray TableArray::createFromJson($jsonP);
$t->check($TableArray$TableArray instanceOf TableArray); 
[0.007 ms]
TableArray::__set_state(array( ))
Ok
create from JSON with key-Path-string as filter 212 $json '{"data":{"user":[{"name":"Meier","likes":3},{"name":"Lehmann","likes":6}]}}';
$data TableArray::createFromJson($json,'data.user')
  ->
fetchAll()
;
$expected = [
  [
'name' => "Meier",'likes' => 3],
  [
'name' => "Lehmann",'likes' => 6]
];
$t->checkEqual($data$expected); 
[0.012 ms]
array ( 0 => array ( 'name' => 'Meier', 'likes' => 3, ), 1 => array ( 'name' => ..
Ok
create from JSON with filter-function 223 $json '{
  "desc":"user",
  "data": {
    "group1":[
      {"name":"Meier","likes":3},
      {"name":"Lehmann","likes":6}
    ],
    "group2": {"name":"Schulz","likes":14}
   }
}'
;
$filter = function($cur){
  return 
array_key_exists('name',$cur) && array_key_exists('likes',$cur);
};
$data TableArray::createFromJson($json$filter)
  ->
fetchAll()
;
$expected = [
 
'data.group1.0' => ['name' => "Meier",'likes' => 3],
 
'data.group1.1' => ['name' => "Lehmann",'likes' => 6],
 
'data.group2' => ['name' => "Schulz",'likes' => 14]
];
$t->checkEqual($data$expected); 
[0.053 ms]
array ( 'data.group1.0' => array ( 'name' => 'Meier', 'likes' => 3, ), 'data.gro ..
Ok
fetch all as JSON-String 247 $json '[{"name":"Meier","likes":3},{"name":"Lehmann","likes":6},{"name":"Schulz","likes":14}]';
$result TableArray::createFromJson($json)
  ->
fetchAllAsJson();
$t->checkEqual($result$json); 
[0.015 ms]
'[{"name":"Meier","likes":3},{"name":"Lehmann","likes":6},{"name":"Schulz","like ..
Ok
json_encode object 253 $json '[{"name":"Meier","likes":3},{"name":"Lehmann","likes":6},{"name":"Schulz","likes":14}]';
$result json_encode(TableArray::createFromJson($json));
$t->checkEqual($result$json); 
[0.010 ms]
'[{"name":"Meier","likes":3},{"name":"Lehmann","likes":6},{"name":"Schulz","like ..
Ok
create from XML-String 258 $strXML '<?xml version="1.0" encoding="utf-8"
<root>
  <row>
    <id>1</id>
    <value>23</value>
  </row>
  <row>
    <id>2</id>
    <value>44</value>
  </row>
</root>'
;
$xmlTableArray TableArray::createFromXml($strXML);
$t->check($xmlTableArray$xmlTableArray instanceOf TableArray); 
[0.158 ms]
TableArray::__set_state(array( ))
Ok
get Array from xmlTableArray 273 $result $xmlTableArray->fetchAll();
$expected = [
  [
'id' => '1''value' => '23'],
  [
'id' => '2''value' => '44']
];
$t->checkEqual($result$expected); 
[0.003 ms]
array ( 0 => array ( 'id' => '1', 'value' => '23', ), 1 => array ( 'id' => '2', ..
Ok
create from Simple-XML 281 $xml simplexml_load_string($strXML);
$xmlTableArray TableArray::createFromXml($xml);
$t->check($xmlTableArray$xmlTableArray instanceOf TableArray); 
[0.022 ms]
TableArray::__set_state(array( ))
Ok
create from XML-String with XPath 286 $strXML '<?xml version="1.0" encoding="utf-8"
<root>
  <data>
    <row>
      <id>1</id>
      <value>34</value>
    </row>
    <data2>  
      <row>
        <id>2</id>
        <value>66</value>
      </row>
    </data2> 
  </data>
</root>'
;
$xmlTableArray TableArray::createFromXml($strXML,'//row');
$result $xmlTableArray->fetchAll();
$expected = [
  [
'id' => '1''value' => '34'],
  [
'id' => '2''value' => '66']
];
$t->checkEqual($result$expected); 
[0.093 ms]
array ( 0 => array ( 'id' => '1', 'value' => '34', ), 1 => array ( 'id' => '2', ..
Ok
create from XML-String with Namespaces 310 $strXML '<?xml version="1.0" encoding="UTF-8"
<example xmlns:xyz="http://example.org">
    <xyz:row>
      <id>1</id>
      <value>23</value>
    </xyz:row>
    <xyz:row>
      <id>2</id>
      <value>44</value>
    </xyz:row>
</example>'
;
$data TableArray::createFromXml($strXML,'//xyz:row')
  ->
fetchAll()
;
$expected = [
  [
'id' => '1''value' => '23'],
  [
'id' => '2''value' => '44']
];
$t->checkEqual($data$expected); 
[0.054 ms]
array ( 0 => array ( 'id' => '1', 'value' => '23', ), 1 => array ( 'id' => '2', ..
Ok
create Object from Iterator 331 $iterator = function(){
  yield [
'name' => 'Meier''likes' => 3];
  yield [
'name' => 'Lehmann''likes' => 6];
  yield [
'name' => 'Schulz','likes' => 14];
};
$iterator $iterator();
$newData TableArray::create($iterator)
  ->
fetchAll();
;
$expected = [
  
=> ['name' => 'Meier''likes' => 3],
  
=> ['name' => 'Lehmann''likes' => 6],
  
=> ['name' => 'Schulz','likes' => 14],
];
$t->checkEqual($newData$expected); 
[0.017 ms]
array ( 0 => array ( 'name' => 'Meier', 'likes' => 3, ), 1 => array ( 'name' => ..
Ok
create from groped array 348 $groupedArray = [
  
2019 => [
    [
'month' => 5'profit' => 2345 ],
    [
'month' => 6'profit' => 134 ]
  ],
  
2020 => [
    [
'month' => 1'profit' => 456 ],
  ]
];
$keys = ['year'];
$newData TableArray::createFromGroupedArray($groupedArray,$keys)
  ->
fetchAll()
;
$expected = [
  [
'year' => 2019,'month' => 5'profit' => 2345 ],
  [
'year' => 2019,'month' => 6'profit' => 134 ],
  [
'year' => 2020,'month' => 1'profit' => 456 ],
];
$t->checkEqual($newData$expected); 
[0.013 ms]
array ( 0 => array ( 'year' => 2019, 'month' => 5, 'profit' => 2345, ), 1 => arr ..
Ok
create from 2 grouped array 369 $groupedArray = [
  
2019 => [
    
=> ['profit' => 2345 ],
    
=> ['profit' => 134 ]
  ],
  
2020 => [
    
=> ['profit' => 456 ],
  ]
];
$keys = ['year','month'];
$newData TableArray::createFromGroupedArray($groupedArray,$keys)
  ->
fetchAll()
;
$expected = [
  [
'year' => 2019,'month' => 5'profit' => 2345 ],
  [
'year' => 2019,'month' => 6'profit' => 134 ],
  [
'year' => 2020,'month' => 1'profit' => 456 ],
];
$t->checkEqual($newData$expected); 
[0.010 ms]
array ( 0 => array ( 'year' => 2019, 'month' => 5, 'profit' => 2345, ), 1 => arr ..
Ok
create from CSV-File 390 //Simulate CSV-File
$csv "1;\"2,5 €\"\r\n2;\"3,45 €\"\r\n";
$fileName $t->simulateFile($csv);

$setOk TableArray::setCsvDefaultOptions(['delimiter'=>';']);
$data TableArray::createFromCsvFile($fileName)
  ->
fetchAll()
;
$expected = [
  [
'1','2,5 €'],
  [
'2','3,45 €']
];
$t->check($data$data == $expected); 
[0.042 ms]
array ( 0 => array ( 0 => '1', 1 => '2,5 €', ), 1 => array ( 0 => '2', 1 => '3 ..
Ok
use object of class in foreach 405 $data = [
  [
'id' => 1'float' => 3.333333333],
  [
'id' => 2'float' => 13.7777777777],
];
$TableArray TableArray::create($data)
  ->
select('id')
  ->
orderBy('id DESC')
;
$newData = [];
foreach(
$TableArray as $key => $row){
  
$newData[$key] = $row;  
}
$expected = [
  [
'id' => 2],
  [
'id' => 1]
];
$t->checkEqual($newData$expected); 
[0.040 ms]
array ( 0 => array ( 'id' => 2, ), 1 => array ( 'id' => 1, ), )
Ok
addKeys: put Keys in a new column 424 $data = [
  
'k1' => ['id' => 1'value' => 23],
  
'k2' => ['id' => 2'value' => 44]
];
$result TableArray::create($data)
  ->
addKeys('key')
  ->
fetchRaw()
;
$expected = [
  
'k1' => ['id' => 1'value' => 23'key' => 'k1'],
  
'k2' => ['id' => 2'value' => 44'key' => 'k2']
];
$t->checkEqual($result$expected); 
[0.005 ms]
array ( 'k1' => array ( 'id' => 1, 'value' => 23, 'key' => 'k1', ), 'k2' => arra ..
Ok
make field to key and remove field 439 $data = [
  [
'id' => 1'value' => 23'key' => 'k1'],
  [
'id' => 2'value' => 44'key' => 'k2']
];
$result TableArray::create($data)
  ->
fieldAsKey('key')
  ->
fetchRaw()
;
$expected = [
  
'k1' => ['id' => 1'value' => 23],
  
'k2' => ['id' => 2'value' => 44]
];
$t->checkEqual($result$expected); 
[0.007 ms]
array ( 'k1' => array ( 'id' => 1, 'value' => 23, ), 'k2' => array ( 'id' => 2, ..
Ok
first Row to Key 454 $dataFromCSV = [
  [
'id','value'],
  [
123],
  [
244]
];
$result TableArray::create($dataFromCSV)
  ->
firstRowToKey()
  ->
fetchRaw();
$expected = [
  [
'id' => 1'value' => 23],
  [
'id' => 2'value' => 44]
];
$t->checkEqual($result$expected); 
[0.005 ms]
array ( 0 => array ( 'id' => 1, 'value' => 23, ), 1 => array ( 'id' => 2, 'value ..
Ok
get first Field Name 469 $data = [
  [
'id' => 1'value' => 23],
  [
'id' => 2'value' => 44]
];
$result TableArray::create($data)
  ->
fieldNameRaw(0);  //0: first
$expected 'id';
$t->checkEqual($result$expected); 
[0.003 ms]
'id'
Ok
get all Field Names 479 $data = [
  [
'id' => 1'value' => 23],
  [
'id' => 2'value' => 44]
];
$result TableArray::create($data)
  ->
fieldNameRaw();  //all
$expected = ['id','value'];
$t->checkEqual($result$expected); 
[0.013 ms]
array ( 0 => 'id', 1 => 'value', )
Ok
reduce multidimensional array to 2 dimensional array 489 $data = [
  [
'id' => 1'@attributes' => ['currency' => "USD",'rate' => "1.1370"]],
  [
'id' => 2'@attributes' => ['currency' => "JPY",'rate' => "1.28"]],
];
$newData TableArray::create($data)
  ->
flatten()
  ->
fetchAll();
$expected = [
  [
'id' => 1'@attributes.currency' => "USD",'@attributes.rate' => "1.1370"],
  [
'id' => 2'@attributes.currency' => "JPY",'@attributes.rate' => "1.28"],
];
$t->checkEqual($newData$expected); 
[0.011 ms]
array ( 0 => array ( 'id' => 1, '@attributes.currency' => 'USD', '@attributes.ra ..
Ok
reduce multidimensional array to 1 dimensional array with flatten and CONCAT 503 $warehouses '[
  {
  "id": 1,
  "name": "warehouse 1",
  "pivot": {
      "product_id": "1",
      "qty": 136.5
      }
  },
  {
  "id": 2,
  "name": "warehouse 2",
  "pivot": {
      "product_id": "1",
      "qty": 71.5
      }
  }
]'
;
$newData TableArray::createFromJson($warehouses)
  ->
flatten()
  ->
select('CONCAT(name," - ",pivot.qty) AS item')
  ->
fetchColumn('item')
;
$expected = ["warehouse 1 - 136.5""warehouse 2 - 71.5"];
$t->checkEqual($newData$expected); 
[0.055 ms]
array ( 0 => 'warehouse 1 - 136.5', 1 => 'warehouse 2 - 71.5', )
Ok
collect childs recursive 532 $data = [
  [
'id' => 1'val' => 11],
  [
      [
'id' => 2'val' => 21],
      [
'id' => 3'val' => 32],
  ],
];
////collects all arrays which have an element with the key 'val' in one level
$newData TableArray::create($data)
  ->
collectChilds(['val'])
  ->
fetchAll()
;

$expected = [
  [
'id' => 1'val' => 11],
  [
'id' => 2'val' => 21],
  [
'id' => 3'val' => 32],
];
$t->checkEqual($newData$expected); 
[0.048 ms]
array ( 0 => array ( 'id' => 1, 'val' => 11, ), 1 => array ( 'id' => 2, 'val' => ..
Ok
collect childs with wildcards 553 $data =  [
  [
'id' => 1'val' => 11],
  [
'a' => [
      [
'id' => 2'val' => 21],
      [
'id' => 3'val' => 32],
  ]],
  [
'b' => [
      [
'id' => 4'val' => 41],
  ]],
];
$newData TableArray::create($data)
->
collectChilds(['a.*.val'])
->
fetchAll()
;
$expected = [
  [
'a' => [
    [
'id' => 2'val' => 21],
    [
'id' => 3'val' => 32],
  ]]
];
$t->checkEqual($newData$expected); 
[0.069 ms]
array ( 0 => array ( 'a' => array ( 0 => array ( 'id' => 2, 'val' => 21, ), 1 => ..
Ok
collect childs and create flatten keys 576 $data = [
  
'a' => ['id' => 1'val' => 11],
  
'b' => [
      
'b0' => ['id' => 2'val' => 21],
      
'b1' => ['id' => 3'val' => 32],
  ],
];
//collects all arrays which have an element with the key 'val' in one level
$newData TableArray::create($data)
  ->
collectChilds(['val'], true)
  ->
fetchAll()
;
$expected = [
  
'a' => ['id' => 1'val' => 11],
  
'b.b0' => ['id' => 2'val' => 21],
  
'b.b1' => ['id' => 3'val' => 32],
];
$t->checkEqual($newData$expected); 
[0.024 ms]
array ( 'a' => array ( 'id' => 1, 'val' => 11, ), 'b.b0' => array ( 'id' => 2, ' ..
Ok
#select rows 596 $data = [
  [
'name' => 'Meier''likes' => 3],
  [
'name' => 'Lehmann''likes' => 6],
  [
'name' => 'Schulz','likes' => 14],
];
$newData TableArray::create($data)
  ->
select('name')
  ->
fetchAll();
 
$expected = [
  [
'name' => 'Meier'],
  [
'name' => 'Lehmann'],
  [
'name' => 'Schulz'],
];
$t->checkEqual($newData$expected); 
[0.012 ms]
array ( 0 => array ( 'name' => 'Meier', ), 1 => array ( 'name' => 'Lehmann', ), ..
Ok
select rows and rename 613 $data = [
  [
'name' => 'Meier''likes' => 3],
  [
'name' => 'Lehmann''likes' => 6],
  [
'name' => 'Schulz','likes' => 14],
];
$newData TableArray::create($data)
  ->
select('name AS Surname')
  ->
fetchAll();
 
$expected = [
  [
'Surname' => 'Meier'],
  [
'Surname' => 'Lehmann'],
  [
'Surname' => 'Schulz'],
];
$t->checkEqual($newData$expected); 
[0.011 ms]
array ( 0 => array ( 'Surname' => 'Meier', ), 1 => array ( 'Surname' => 'Lehmann ..
Ok
select rows with other column-order 630 $data = [
  [
'name' => 'Meier''likes' => 3],
  [
'name' => 'Lehmann''likes' => 6],
];
$newData TableArray::create($data)
  ->
select('likes,name')
  ->
fetchAll();
 
$expected = [
  [
'likes' => 3,'name' => 'Meier'],
  [
'likes' => 6,'name' => 'Lehmann'],
];
$t->checkEqual($newData$expected); 
[0.010 ms]
array ( 0 => array ( 'likes' => 3, 'name' => 'Meier', ), 1 => array ( 'likes' => ..
Ok
select and add column with function UPPER 649 $data = [
  [
'name' => 'Meier''likes' => 3],
  [
'name' => 'Lehmann''likes' => 6],
];
$newData TableArray::create($data)
  ->
select('name,UPPER(name) as uppername,likes')
  ->
fetchAll();
 
$expected = [
 [
'name' => 'Meier','uppername' => 'MEIER''likes' => 3],
 [
'name' => 'Lehmann','uppername' => 'LEHMANN''likes' => 6],
];
$t->checkEqual($newData$expected); 
[0.031 ms]
array ( 0 => array ( 'name' => 'Meier', 'uppername' => 'MEIER', 'likes' => 3, ), ..
Ok
select and add column with function LOWER 664 $data = [
  [
'name' => 'Meier''likes' => 3],
  [
'name' => 'Lehmann''likes' => 6],
];
$newData TableArray::create($data)
  ->
select('name,LOWER(name) as lowername,likes')
  ->
fetchAll();
 
$expected = [
 [
'name' => 'Meier','lowername' => 'meier''likes' => 3],
 [
'name' => 'Lehmann','lowername' => 'lehmann''likes' => 6],
];
$t->checkEqual($newData$expected); 
[0.019 ms]
array ( 0 => array ( 'name' => 'Meier', 'lowername' => 'meier', 'likes' => 3, ), ..
Ok
select and add column with function FORMAT 679 $data = [
  [
'id' => 1'float' => 3.333333333],
  [
'id' => 2'float' => 13.7777777777],
];
$newData TableArray::create($data)
  ->
select('id,FORMAT("%05.2f",float) as val')
  ->
fetchAll();
 
$expected = [
  [
'id' => 1'val' => "03.33"],
  [
'id' => 2'val' => "13.78"],
];
$t->checkEqual($newData$expected); 
[0.028 ms]
array ( 0 => array ( 'id' => 1, 'val' => '03.33', ), 1 => array ( 'id' => 2, 'va ..
Ok
select and concat fields with function FORMAT 694 $data = [
  [
'id' => 1'float' => 3.333333333],
  [
'id' => 2'float' => 13.7777777777],
];

$newData TableArray::create($data)
  ->
select('id,FORMAT("%d:%05.2f",id,float) as val')
  ->
fetchAll();
 
$expected = [
  [
'id' => 1'val' => "1:03.33"],
  [
'id' => 2'val' => "2:13.78"],
];
$t->checkEqual($newData$expected); 
[0.024 ms]
array ( 0 => array ( 'id' => 1, 'val' => '1:03.33', ), 1 => array ( 'id' => 2, ' ..
Ok
select and use DATEFORMAT with a datestring 710 $testDate '2021-01-20 14:15:16';
$arr TableArray::create([['date' => $testDate ]])
  ->
select("DATEFORMAT('Y-m-d H:i:s',date) as testDate")
  ->
fetchColumn('testDate')
;
$t->checkEqual($arr, [$testDate]); 
[0.075 ms]
array ( 0 => '2021-01-20 14:15:16', )
Ok
select and use DATEFORMAT with a Timestamp 719 $testDate '2021-01-20 14:15:16';
$timestamp strtotime($testDate);
$arr TableArray::create([['ts' => $timestamp ]])
  ->
select("DATEFORMAT('Y-m-d H:i:s',ts) as testDate")
  ->
fetchColumn('testDate')
;
$t->checkEqual($arr, [$testDate]); 
[0.030 ms]
array ( 0 => '2021-01-20 14:15:16', )
Ok
select and use DATEFORMAT with a ms-Timestamp 728 $testDate '2022-01-05 14:15:16';
$ms_timestamp strtotime($testDate) * 1000;
$arr TableArray::create([['ts' => $ms_timestamp ]])
  ->
select("DATEFORMAT('Y-m-d H:i:s',ts,'ms') as testDate")
  ->
fetchColumn('testDate')
;
$t->checkEqual($arr, [$testDate]); 
[0.028 ms]
array ( 0 => '2022-01-05 14:15:16', )
Ok
select and use DATEFORMAT with UTC-Time and a ms-Timestamp 737 $testDate '2021-01-20 14:15:16';
$msTimestamp strtotime($testDate.'UTC') * 1000;
$arr TableArray::create([['ts' => $msTimestamp]])
  ->
select("DATEFORMAT('Y-m-d H:i:s',ts,'msUTC') as testDate")
  ->
fetchColumn('testDate')
;
$t->checkEqual($arr, [$testDate]); 
[0.041 ms]
array ( 0 => '2021-01-20 14:15:16', )
Ok
select and manipulate fields with REPLACE 748 $data = [
  [
'id' => 1'price' => '4 Eur'],
  [
'id' => 2'price' => '5 Eur'],
];
$newData TableArray::create($data)
  ->
select('id,REPLACE("Eur","€",price) as price')
  ->
fetchAll();
 
$expected = [
  [
'id' => 1'price' => '4 €'],
  [
'id' => 2'price' => '5 €'],
];
$t->checkEqual($newData$expected); 
[0.025 ms]
array ( 0 => array ( 'id' => 1, 'price' => '4 €', ), 1 => array ( 'id' => 2, ' ..
Ok
use ABS Function in SELECT 763 $data = [
  [
'value' => -34.7],
  [
'value' => 4.6],
];
$newData TableArray::create($data)
  ->
select('ABS(value) as absValue')
  ->
fetchAll()
;
$expected = [
  [
'absValue' => 34.7],
  [
'absValue' => 4.6],
];
$t->checkEqual($newData$expected); 
[0.018 ms]
array ( 0 => array ( 'absValue' => 34.7, ), 1 => array ( 'absValue' => 4.6, ), )
Ok
use INTVAL Function 778 $data = [
  [
'value' => -34.7],
];
$newData TableArray::create($data)
  ->
select('INTVAL(value) as int')
  ->
fetchRow()  //first Row
;
$expected = ['int' => -34];
$t->checkEqual($newData$expected); 
[0.024 ms]
array ( 'int' => -34, )
Ok
use INTVAL Function convert hex 789 $data = [
  [
'value' => '1c'],
];
$newData TableArray::create($data)
  ->
select('INTVAL(value,"16") as int')
  ->
fetchRow()  //first Row
;
$expected = ['int' => 28];
$t->checkEqual($newData$expected); 
[0.018 ms]
array ( 'int' => 28, )
Ok
use INTVAL detection 0x 0b .. 800 $data = [
  [
'value' => '0x10'],  //16
  
['value' => '10'],
  [
'value' => '010'],  //8
  
['value' => '0b110']  //6
];
$newData TableArray::create($data)
  ->
select('INTVAL(value,"0") as int')
  ->
fetchAll()  
;
$expected = [
  [
'int' => 16], 
  [
'int' => 10],
  [
'int' => 8], 
  [
'int' => 6
];
$t->checkEqual($newData$expected); 
[0.019 ms]
array ( 0 => array ( 'int' => 16, ), 1 => array ( 'int' => 10, ), 2 => array ( ' ..
Ok
FLOATVAL from number-format 819 $data = [
  [
'price' => '23.123,87']  //23123.87
];
$newData TableArray::create($data)
  ->
select("FLOATVAL(price,',','.') AS priceval")
  ->
fetchRow();
  
$expected = ['priceval' => 23123.87];
$t->checkEqual($newData$expected); 
[0.021 ms]
array ( 'priceval' => 23123.87, )
Ok
select and use FLOATVAL and SUBSTR 829 $data = [
  [
'id' => 1'price' => '4.5 €'],
  [
'id' => 2'price' => '5 $'],
];
$newData TableArray::create($data)
  ->
select("id, FLOATVAL(price) AS priceval, SUBSTR(price,'-1') AS currency")
  ->
fetchAll();
 
$expected = [
  [
'id' => 1'priceval' => 4.5'currency' => '€'],
  [
'id' => 2'priceval' => 5'currency' => '$'],
];
$t->check($newData$newData == $expected); 
[0.046 ms]
array ( 0 => array ( 'id' => 1, 'priceval' => 4.5, 'currency' => '€', ), 1 => ..
Ok
select and use TRIM 844 $data = [
  [
'id' => 1'price' => '4.5 €'],
  [
'id' => 2'price' => '5 $'],
];
$newData TableArray::create($data)
  ->
select("id, TRIM(price,' €$') AS price")
  ->
fetchAll();
 
$expected = [
  [
'id' => 1'price' => '4.5'],
  [
'id' => 2'price' => '5', ],
];
$t->check($newData$newData == $expected); 
[0.021 ms]
array ( 0 => array ( 'id' => 1, 'price' => '4.5', ), 1 => array ( 'id' => 2, 'pr ..
Ok
select and use SCALE with a factor 859 $data = [
  [
'id' => 1'value' => 45],
  [
'id' => 2'value' => 35],
];
$newData TableArray::create($data)
  ->
select("id, SCALE(value,'0.1') AS val")
  ->
fetchAll();
 
$expected = [ //val = value * 0.1
  
['id' => 1'val' => 4.5],
  [
'id' => 2'val' => 3.5],
];
$t->check($newData$newData == $expected); 
[0.020 ms]
array ( 0 => array ( 'id' => 1, 'val' => 4.5, ), 1 => array ( 'id' => 2, 'val' = ..
Ok
select and use SCALE with a factor and add 874 $data = [ // val = value *0.01 + 0.002
  
['id' => 1'value' => 245],
  [
'id' => 2'value' => 635],
];
$newData TableArray::create($data)
  ->
select("id, SCALE(value,'0.01','0.002') AS val")
  ->
fetchAll();
 
$expected = [ //val = value * 0.1
  
['id' => 1'val' => 2.452],
  [
'id' => 2'val' => 6.352],
];
$t->check($newData$newData == $expected); 
[0.024 ms]
array ( 0 => array ( 'id' => 1, 'val' => 2.452, ), 1 => array ( 'id' => 2, 'val' ..
Ok
SCALE with a factor, add and format 889 $data = [ // val = value *0.01 + 0.002
  
['id' => 1'value' => 245],
  [
'id' => 2'value' => 635],
];
$newData TableArray::create($data)
  ->
select("id, SCALE(value,'0.01','0.002','%.2f') AS val")
  ->
fetchAll();
 
$expected = [ //val = value * 0.1
  
['id' => 1'val' => 2.45],
  [
'id' => 2'val' => 6.35],
];
$t->check($newData$newData == $expected); 
[0.039 ms]
array ( 0 => array ( 'id' => 1, 'val' => '2.45', ), 1 => array ( 'id' => 2, 'val ..
Ok
NULLCOUNT 904 $data = [ 
  [
'id' => 1'value' => 245'value2' => 55],
  [
'id' => 2'value' => 245'value2' => null],
  [
'id' => 3'value' => null'value2' =>null],
];
$newData TableArray::create($data)
  ->
select("id, NULLCOUNT(id,value,value2) AS nullRows")
  ->
fetchAll();

$expected = [
  [
'id' => 1,'nullRows' => 0],
  [
'id' => 2,'nullRows' => 1],
  [
'id' => 3,'nullRows' => 2],
];
$t->check($newData$newData == $expected); 
[0.023 ms]
array ( 0 => array ( 'id' => 1, 'nullRows' => 0, ), 1 => array ( 'id' => 2, 'nul ..
Ok
CONCAT 921 $data = [ 
  [
'id' => 1'value' => 'x''value2' => 55],
  [
'id' => 2'value' => 'Z''value2' => null],
  [
'id' => 3'value' => 's''value2' => 't'],
];
$newData TableArray::create($data)
  ->
select("id, CONCAT(value,value2) AS concatval")
  ->
fetchAll();

$expected = [
  [
'id' => 1,'concatval' => 'x55'],
  [
'id' => 2,'concatval' => 'Z'],
  [
'id' => 3,'concatval' => 'st'],
];
$t->check($newData$newData == $expected); 
[0.019 ms]
array ( 0 => array ( 'id' => 1, 'concatval' => 'x55', ), 1 => array ( 'id' => 2, ..
Ok
select multiple times 938 $data = [
  [
'id' => "1",'date' => "2020-04-01",'time' => "14:03",'userId' => 14'action' => "login"],
  [
'id' => "2",'date' => "2020-04-01",'time' => "14:45",'userId' => 14'action' => "logout"],
];

$newData TableArray::create($data)
  ->
SELECT("CONCAT(date,' ',time) AS datetime"//date + time -> datetime
  
->SELECT("userId,action,DATEFORMAT('d.m.Y H:i:s',datetime) as date")
  ->
fetchAll()
;
$expected = [
  [
'userId' => 14'action' => "login"'date' => "01.04.2020 14:03:00"],
  [
'userId' => 14'action' => "logout"'date' => "01.04.2020 14:45:00"],
];
$t->check($newData$newData == $expected); 
[0.050 ms]
array ( 0 => array ( 'userId' => 14, 'action' => 'login', 'date' => '01.04.2020 ..
Ok
SPLIT price and currency 955 $data = [
  [
'1','2.5 €'],
  [
'2','3.45 €']
];
$newData TableArray::create($data)
  ->
select("0 as id, SPLIT(1,' ','0') AS price, SPLIT(1,' ','1') as currency")
  ->
fetchAll()
;
$expected = [
  [
'id' => '1','price' => '2.5''currency' => '€'],
  [
'id' => '2','price' => '3.45''currency' => '€'],
];
$t->checkEqual($newData$expected); 
[0.056 ms]
array ( 0 => array ( 'id' => '1', 'price' => '2.5', 'currency' => '€', ), 1 => ..
Ok
Create a list from array with implode 971 $data = [
  [
'name' => 'scool 25''school_subjects' => ['English','maths','science']],
  [
'name' => 'scool 26''school_subjects' => ['English','maths','history']],
];
$newData TableArray::create($data)
  ->
select("name, IMPLODE(school_subjects) AS subjectlist")
  ->
FilterLikeIn('subjectlist','science')
  ->
fetchAll();

$expected = [
  [
'name' => 'scool 25''subjectlist' => 'English,maths,science'],
];
$t->check($newData$newData == $expected); 
[0.028 ms]
array ( 0 => array ( 'name' => 'scool 25', 'subjectlist' => 'English,maths,scien ..
Ok
list from array recursive with implode 986 $data = [
  [
'id' => 1'values' => ['A',['B','C']]]
]; 
$newData TableArray::create($data)
  ->
select("IMPLODE(values) AS letter")
  ->
fetchRow()
;
$expected = ['letter' => "A,B,C"];
$t->checkEqual($newData$expected); 
[0.027 ms]
array ( 'letter' => 'A,B,C', )
Ok
Use PHP-Function as user-Funktion 998 $data = [
  [
'id' => 1'name' => 'abc'],
  [
'id' => 2'name' => 'bla'],
];
$newData TableArray::create($data)
  ->
addSqlFunction('MD5','md5')
  ->
select("id, name, MD5(name) AS hash")
  ->
fetchAll();
 
$expected = [
  [
'id' => 1'name' => 'abc''hash' => md5('abc')],
  [
'id' => 2'name' => 'bla''hash' => md5('bla')]
];
$t->check($newData$newData == $expected); 
[0.023 ms]
array ( 0 => array ( 'id' => 1, 'name' => 'abc', 'hash' => '900150983cd24fb0d696 ..
Ok
select and add column with user-function 1014 $data = [
  [
'id' => 1'val' => 3'factor' => 4.5],
  [
'id' => 1'val' => 6'factor' => 1.0],
];
$newData TableArray::create($data)
  ->
addSqlFunction('mul',function($v1,$v2){return $v1*$v2;})
  ->
select('id,val,factor,mul(val,factor) as product')
  ->
fetchAll();
 
$expected = [
  [
'id' => 1'val' => 3'factor' => 4.5'product' => 13.5],
  [
'id' => 1'val' => 6'factor' => 1.0'product' => 6.0],
];
$t->checkEqual($newData$expected); 
[0.031 ms]
array ( 0 => array ( 'id' => 1, 'val' => 3, 'factor' => 4.5, 'product' => 13.5, ..
Ok
select and add column with user-function with use 1030 $data = [
  [
'id' => 1'val' => 3],
  [
'id' => 1'val' => 6],
];

$factor 2;
$newData TableArray::create($data)
  ->
addSqlFunction('mul',function($val) use($factor){return $val $factor;})
  ->
select('id,val,mul(val) as product')
  ->
fetchAll();
 
$expected = [
  [
'id' => 1'val' => 3'product' => 6],
  [
'id' => 1'val' => 6'product' => 12],
];
$t->checkEqual($newData$expected); 
[0.016 ms]
array ( 0 => array ( 'id' => 1, 'val' => 3, 'product' => 6, ), 1 => array ( 'id' ..
Ok
select with accumulated sum in extra column 1048 $data = [
  [
'id' => 1'val' => 3],
  [
'id' => 2'val' => 6],
  [
'id' => 3'val' => 4],
];
$sum 0;
$newData TableArray::create($data)
  ->
addSqlFunction('sum',function($val) use(&$sum){
      
$sum += $val;
      return 
$sum;
    })
  ->
select('val,sum(val) as sum')
  ->
fetchAll();
$expected = [
  [
'val' => 3'sum' => 3],
  [
'val' => 6'sum' => 9],
  [
'val' => 4'sum' => 13],
];  
$t->checkEqual($newData$expected); 
[0.023 ms]
array ( 0 => array ( 'val' => 3, 'sum' => 3, ), 1 => array ( 'val' => 6, 'sum' = ..
Ok
add Functions with array 1069 $fileFunctions = [
  
'BASENAME' => 'basename',
  
'DIRNAME'  => 'dirname',
];
$TableArray TableArray::create()
  ->
addSqlFunctionFromArray($fileFunctions)
;
$checkOk $TableArray->getSqlFunction('BASENAME') !== false AND 
  
$TableArray->getSqlFunction('DIRNAME') !== false;
$t->checkEqual($checkOktrue); 
[0.006 ms]
true
Ok
#orderBy : simple sort string ASC 1081 $data = [
  [
'name' => 'Meier''likes' => 3],
  [
'name' => 'Lehmann''likes' => 6],
  [
'name' => 'Schulz','likes' => 14],
];
$newData TableArray::create($data)
  ->
orderBy('name')
  ->
fetchAll();
 
$expected = [
   [
'name' => 'Lehmann''likes' => 6],
   [
'name' => 'Meier''likes' => 3],
   [
'name' => 'Schulz','likes' => 14],
];
$t->checkEqual($newData$expected); 
[0.033 ms]
array ( 0 => array ( 'name' => 'Lehmann', 'likes' => 6, ), 1 => array ( 'name' = ..
Ok
select and sort string ASC 1098 $data = [
  [
'name' => 'Meier''likes' => 3],
  [
'name' => 'Lehmann''likes' => 6],
  [
'name' => 'Schulz','likes' => 14],
];
$newData TableArray::create($data)
  ->
select('likes')
  ->
orderBy('name')
  ->
fetchAll();
 
$expected = [
  [
'likes' => 6],
  [
'likes' => 3],
  [
'likes' => 14],
];
$t->checkEqual($newData$expected); 
[0.012 ms]
array ( 0 => array ( 'likes' => 6, ), 1 => array ( 'likes' => 3, ), 2 => array ( ..
Ok
simple sort string DESC 1117 $newData TableArray::create($data)
  ->
orderBy('name DESC')
  ->
fetchAll();
 
$expected = [
  [
'name' => 'Schulz','likes' => 14],
  [
'name' => 'Meier''likes' => 3],
  [
'name' => 'Lehmann''likes' => 6],
];
$t->checkEqual($newData$expected); 
[0.011 ms]
array ( 0 => array ( 'name' => 'Schulz', 'likes' => 14, ), 1 => array ( 'name' = ..
Ok
simple sort number DESC 1129 $newData TableArray::create($data)
  ->
orderBy('likes DESC')
  ->
fetchAll();
$expected = [
  [
'name' => 'Schulz','likes' => 14],
  [
'name' => 'Lehmann''likes' => 6],
  [
'name' => 'Meier''likes' => 3],
];
$t->checkEqual($newData$expected); 
[0.021 ms]
array ( 0 => array ( 'name' => 'Schulz', 'likes' => 14, ), 1 => array ( 'name' = ..
Ok
sort NATURAL 1140 $data = [
  [
'name' => 'A1''likes' => 3],
  [
'name' => 'A12''likes' => 6],
  [
'name' => 'A2','likes' => 14],
  [
'name' => 'A14','likes' => 7],
];
$newData TableArray::create($data)
  ->
orderBy('name NATURAL')
  ->
fetchAll();
$expected = [
  [
'name' => 'A1''likes' => 3],
  [
'name' => 'A2','likes' => 14],
  [
'name' => 'A12''likes' => 6],
  [
'name' => 'A14','likes' => 7],
];
$t->checkEqual($newData$expected); 
[0.013 ms]
array ( 0 => array ( 'name' => 'A1', 'likes' => 3, ), 1 => array ( 'name' => 'A2 ..
Ok
sort 2 criteria 1158 $data = [
  [
'name' => 'A''likes' => 3],
  [
'name' => 'B''likes' => 6],
  [
'name' => 'A','likes' => 14],
];
$newData TableArray::create($data)
  ->
orderBy('name,likes')
  ->
fetchAll();
$expected = [
  [
'name' => 'A''likes' => 3],
  [
'name' => 'A','likes' => 14],
  [
'name' => 'B''likes' => 6],
];
$t->checkEqual($newData$expected); 
[0.012 ms]
array ( 0 => array ( 'name' => 'A', 'likes' => 3, ), 1 => array ( 'name' => 'A', ..
Ok
sort first ASC, second DESC 1174 $data = [
  [
'name' => 'A''likes' => 3],
  [
'name' => 'B''likes' => 6],
  [
'name' => 'A','likes' => 14],
];
$newData TableArray::create($data)
  ->
orderBy('name ASC,likes DESC')
  ->
fetchAll();
$expected = [
  [
'name' => 'A','likes' => 14],
  [
'name' => 'A''likes' => 3],
  [
'name' => 'B''likes' => 6],
];
$t->checkEqual($newData$expected); 
[0.011 ms]
array ( 0 => array ( 'name' => 'A', 'likes' => 14, ), 1 => array ( 'name' => 'A' ..
Ok
sort num. Array first ASC, second DESC 1190 $data = [
  [
'A'3],
  [
'B'6],
  [
'A'14],
];
$newData TableArray::create($data)
  ->
orderBy('0 ASC,1 DESC')
  ->
fetchAll();
$expected = [
  [
'A'14],
  [
'A',  3],
  [
'B'6],
];
$t->checkEqual($newData$expected); 
[0.024 ms]
array ( 0 => array ( 0 => 'A', 1 => 14, ), 1 => array ( 0 => 'A', 1 => 3, ), 2 = ..
Ok
sort with LIKE-function 1206 $data = [
  [
'name' => 'A''pos' => '2'],
  [
'name' => 'B''pos' => '3.ceo'],
  [
'name' => 'C','pos' => '10'],
];
$newData TableArray::create($data)
  ->
orderBy("LIKE(pos,'%CEO%') DESC,pos ASC")
  ->
fetchAll();
$expected = [
  [
'name' => 'B''pos' => '3.ceo'],
  [
'name' => 'A''pos' => '2'],
  [
'name' => 'C','pos' => '10'],
];
$t->checkEqual($newData$expected); 
[0.057 ms]
array ( 0 => array ( 'name' => 'B', 'pos' => '3.ceo', ), 1 => array ( 'name' => ..
Ok
sort with DATEFORMAT-function 1222 $data = [
  [
'name' => 'A''date' => '1.1.2018'],
  [
'name' => 'B''date' => '23.6.2017'],
  [
'name' => 'C','date' => '31.1.2006'],
];
$newData TableArray::create($data)
  ->
orderBy("DATEFORMAT('Y-m-d',date) ASC")
  ->
fetchAll();
$expected = [
  [
'name' => 'C','date' => '31.1.2006'],
  [
'name' => 'B''date' => '23.6.2017'],
  [
'name' => 'A''date' => '1.1.2018'],
];
$t->checkEqual($newData$expected); 
[0.040 ms]
array ( 0 => array ( 'name' => 'C', 'date' => '31.1.2006', ), 1 => array ( 'name ..
Ok
sort with user Function 1238 $data = [
  [
'name' => 'A''pos' => '2'],
  [
'name' => 'B''pos' => '1.ceo'],
  [
'name' => 'C','pos' => '1'],
];
$newData TableArray::create($data)
  ->
addSqlFunction('ceoFirst',function($val){return (stripos($val,'ceo') !== false "A" "B");})
  ->
orderBy('ceoFirst(pos),pos')
  ->
fetchAll();
$expected = [
  [
'name' => 'B''pos' => '1.ceo'],
  [
'name' => 'C','pos' => '1'],
  [
'name' => 'A''pos' => '2'],
];
$t->checkEqual($newData$expected); 
[0.043 ms]
array ( 0 => array ( 'name' => 'B', 'pos' => '1.ceo', ), 1 => array ( 'name' => ..
Ok
sort with user Function name C,D,B,A 1255 $data = [
  [
'name' => 'A''pos' => '2'],
  [
'name' => 'B''pos' => '1.ceo'],
  [
'name' => 'C','pos' => '1'],
  [
'name' => 'D','pos' => '3'],
];
$newData TableArray::create($data)
  ->
addSqlFunction('cdba',function($val){
      
$atFirst = ["C","D","B","A"];
      
$i array_search($val,$atFirst);
      return 
$i !== false $i 999;
    })
  ->
orderBy('cdba(name)')
  ->
fetchAll();
$expected = [
  [
'name' => 'C','pos' => '1'],
  [
'name' => 'D','pos' => '3'],
  [
'name' => 'B''pos' => '1.ceo'],
  [
'name' => 'A''pos' => '2'],
];
$t->checkEqual($newData$expected); 
[0.021 ms]
array ( 0 => array ( 'name' => 'C', 'pos' => '1', ), 1 => array ( 'name' => 'D', ..
Ok
complex example 1278 $refData = [
  
"Ref0",
  
"Ref1",
  
"Z-Ref2",
  
"A-Ref3"
];
$data = [
  [
'name' => 'A''ref' => 2],
  [
'name' => 'B''ref' => 3],
];
$newData TableArray::create($data)
  ->
addSqlFunction('refFrom',function($val)use($refData){return $refData[$val];})
  ->
select('name,ref,refFrom(ref) as refVal')
  ->
orderBy('refVal')
  ->
fetchAll();
  
$expected = [  
  [
'name' => "B"'ref' => 3'refVal' => "A-Ref3"],
  [
'name' => "A"'ref' => 2'refVal' => "Z-Ref2"],
 ];
$t->checkEqual($newData$expected); 
[0.024 ms]
array ( 0 => array ( 'name' => 'B', 'ref' => 3, 'refVal' => 'A-Ref3', ), 1 => ar ..
Ok
fetchKeyValue 1301 $data = [
  [
'id' => "1",'name' => "monitor",'quantity' => "1",'orderId' => "1"],
  [
'id' => "2",'name' => "headset",'quantity' => "5",'orderId' => "1"],
  [
'id' => "3",'name' => "PC",'quantity' => "2",'orderId' => "2"],
  [
'id' => "4",'name' => "Maus",'quantity' => "3",'orderId' => "2"],
];
$newData TableArray::create($data)->fetchKeyValue('id','name');
$expected = [
  
=> "monitor",
  
=> "headset",
  
=> "PC",
  
=> "Maus",
];
$t->checkEqual($newData$expected); 
[0.005 ms]
array ( 1 => 'monitor', 2 => 'headset', 3 => 'PC', 4 => 'Maus', )
Ok
example createFromOneDimArray and fetchKeyValue 1317 $dates = [
   
"2019-09-11" => 1,
   
"2019-10-12" => 3,
   
"2019-09-14" => 4,
];
$newData TableArray::createFromOneDimArray($dates)
  ->
select('DATEFORMAT("M Y",0) AS group, 1')
  ->
filterGroupAggregate([=> 'sum'],['group'])
  ->
orderBy('DATEFORMAT("Y-m",group) DESC')
  ->
fetchKeyValue('group',1)
;
$expected = [
  
'Oct 2019' => 3,
  
'Sep 2019' => 5,
];
$t->checkEqual($newData$expected); 
[0.086 ms]
array ( 'Oct 2019' => 3, 'Sep 2019' => 5, )
Ok
fetchRow without Key 1335 $data = [
  [
'id' => "1",'name' => "monitor"],
  [
'id' => "2",'name' => "headset"],
];
$newData TableArray::create($data)
  ->
select('name')
  ->
fetchRow()
;
$expected = ['name' => "monitor"];  //first row
$t->checkEqual($newData$expected); 
[0.009 ms]
array ( 'name' => 'monitor', )
Ok
fetchRow with Key 1347 $data = [
  [
'id' => "1",'name' => "monitor"],
  [
'id' => "2",'name' => "headset"],
];
$newData TableArray::create($data)
  ->
fetchRow(1//second row
;
$expected = ['id' => "2",'name' => "headset"]; 
$t->checkEqual($newData$expected); 
[0.005 ms]
array ( 'id' => '2', 'name' => 'headset', )
Ok
fetchRow with unknown Key 1358 $data = [
  [
'id' => "1",'name' => "monitor"],
  [
'id' => "2",'name' => "headset"],
];
$newData TableArray::create($data)
  ->
fetchRow(5
;
$expected false
$t->checkEqual($newData$expected); 
[0.007 ms]
false
Ok
fetchColumn 1369 $data = [
  [
'id' => "1",'name' => "monitor",'quantity' => "1",'orderId' => "1"],
  [
'id' => "2",'name' => "headset",'quantity' => "5",'orderId' => "1"],
  [
'id' => "3",'name' => "PC",'quantity' => "2",'orderId' => "2"],
  [
'id' => "4",'name' => "Maus",'quantity' => "3",'orderId' => "2"],
];
$newData TableArray::create($data)->fetchColumn('quantity');
$expected = ["1","5","2","3"];
$t->checkEqual($newData$expected); 
[0.003 ms]
array ( 0 => '1', 1 => '5', 2 => '2', 3 => '3', )
Ok
fetchColumnUnique 1380 $data = [
  [
'id' => "1",'name' => "monitor",'quantity' => "1",'orderId' => "1"],
  [
'id' => "2",'name' => "headset",'quantity' => "5",'orderId' => "1"],
  [
'id' => "3",'name' => "monitor",'quantity' => "2",'orderId' => "2"],
];
$newData TableArray::create($data)->fetchColumnUnique('name');
$expected = ["headset","monitor"];
$t->checkEqual($newData$expected); 
[0.025 ms]
array ( 0 => 'headset', 1 => 'monitor', )
Ok
fetchGroup 1391 $data = [
  [
'id' => "1",'name' => "monitor",'quantity' => "1",'orderId' => "1"],
  [
'id' => "2",'name' => "headset",'quantity' => "5",'orderId' => "1"],
  [
'id' => "3",'name' => "PC",'quantity' => "2",'orderId' => "2"],
  [
'id' => "4",'name' => "Maus",'quantity' => "3",'orderId' => "2"],
];
$newData TableArray::create($data)->fetchGroup(['orderId']);
$expected = [
  
=> [
    
=> ['id' => "1",'name' => "monitor",'quantity' => "1",'orderId' => "1"],
    
=> ['id' => "2",'name' => "headset",'quantity' => "5",'orderId' => "1"],
  ],
  
=> [
    
=>['id' => "3",'name' => "PC",'quantity' => "2",'orderId' => "2"],
    
=>['id' => "4",'name' => "Maus",'quantity' => "3",'orderId' => "2"],
  ]
];
$t->checkEqual($newData$expected); 
[0.010 ms]
array ( 1 => array ( 0 => array ( 'id' => '1', 'name' => 'monitor', 'quantity' = ..
Ok
concat two fields and fetchGroup 1411 $data = [
  [
'id' => "1",'date' => "2020-04-01",'time' => "14:45",'userId' => 1'action' => "login"],
  [
'id' => "2",'date' => "2020-04-01",'time' => "14:45",'userId' => 2'action' => "logout"],
  [
'id' => "3",'date' => "2020-04-01",'time' => "16:33",'userId' => 1'action' => "logout"],
];

$newData TableArray::create($data)
  ->
SELECT("id, userId, action, CONCAT(date,' ',time) AS datetime")
  ->
fetchgroup(['datetime'])
;
$expected = [
  
'2020-04-01 14:45' => [
    
=> ['id' => "1",'userId' => 1'action' => "login"'datetime' => "2020-04-01 14:45"],
    
=> ['id' => "2",'userId' => 2'action' => "logout"'datetime' => "2020-04-01 14:45"],
  ],
  
'2020-04-01 16:33' => [
    
=> ['id' => "3",'userId' => 1'action' => "logout"'datetime' => "2020-04-01 16:33"],
  ]
];
$t->checkEqual($newData$expected); 
[0.035 ms]
array ( '2020-04-01 14:45' => array ( 0 => array ( 'id' => '1', 'userId' => 1, ' ..
Ok
fetchGroup 2 groups 1433 $data = [
  [
'id' => "1",'name' => "monitor",'cat' => "A",'orderId' => "1"],
  [
'id' => "2",'name' => "headset",'cat' => "B",'orderId' => "1"],
  [
'id' => "3",'name' => "PC",'cat' => "A",'orderId' => "2"],
  [
'id' => "4",'name' => "Maus",'cat' => "A",'orderId' => "2"],
];
$newData TableArray::create($data)->fetchGroup(['orderId','cat']);
$expected = [
  
=> [
    
'A' => [
        
=> ['id' => "1",'name' => "monitor",'cat' => "A",'orderId' => "1"]
    ],
    
'B' => [
        
=> ['id' => "2",'name' => "headset",'cat' => "B",'orderId' => "1"]
    ],
  ],
  
=> [
    
'A' => [
       
=>['id' => "3",'name' => "PC",'cat' => "A",'orderId' => "2"],
       
=>['id' => "4",'name' => "Maus",'cat' => "A" ,'orderId' => "2"]
    ]
  ]
];
$t->checkEqual($newData$expected); 
[0.019 ms]
array ( 1 => array ( 'A' => array ( 0 => array ( 'id' => '1', 'name' => 'monitor ..
Ok
data with objects 1460 $data = [ 
  (object)[
'name' => 'Meier''likes' => 3], 
  (object)[
'name' => 'Lehmann''likes' => 6], 
  (object)[
'name' => 'Schulz','likes' => 14], 
]; 
$sqlObj TableArray::create($data);

$expected = [ 
  [
'name' => 'Meier''likes' => 3], 
  [
'name' => 'Lehmann''likes' => 6], 
  [
'name' => 'Schulz','likes' => 14], 
]; 

$t->checkEqual($sqlObj->fetchAll(), $expected); 
[0.007 ms]
array ( 0 => array ( 'name' => 'Meier', 'likes' => 3, ), 1 => array ( 'name' => ..
Ok
get array of objects 1476 $data = [ 
  [
'name' => 'Meier''likes' => 3], 
  [
'name' => 'Lehmann''likes' => 6], 
  [
'name' => 'Schulz','likes' => 14], 
]; 
$newData TableArray::create($data)->fetchAllObj();

$expected = [ 
  (object)[
'name' => 'Meier''likes' => 3], 
  (object)[
'name' => 'Lehmann''likes' => 6], 
  (object)[
'name' => 'Schulz','likes' => 14], 
]; 

$t->check($newData$newData == $expected); 
[0.010 ms]
array ( 0 => (object) array( 'name' => 'Meier', 'likes' => 3, ), 1 => (object) a ..
Ok
fetchAllAsCsv with default options 1492 $data = [
  [
'id' => '1','price' => '2,5 €'],
  [
'id' => '2','price' => '3,45 €']
];
TableArray::setCsvDefaultOptions(['delimiter'=>';']);
$csv TableArray::create($data)
  ->
fetchAllAsCsv()
;
//BOM at first, Semicolon as delimiter, "\r\n" as eol was set
$expected "\xef\xbb\xbf1;\"2,5 €\"\r\n2;\"3,45 €\"\r\n";
$t->checkEqual($csv,$expected); 
[0.025 ms]
'1;"2,5 €" 2;"3,45 €" '
Ok
fetchAllAsCsv with options 1505 $data = [
  [
'id' => '1','price' => '2,5 €'],
  [
'id' => '2','price' => '3,45 €']
];
$csv TableArray::create($data)
  ->
setOption([
    
'title'=>true,
    
'bom' => false,
    
'delimiter' => ",",
    
'eol' => "\n"
  
])
  ->
fetchAllAsCsv()
;
$expected =     "id,price\n1,\"2,5 €\"\n2,\"3,45 €\"\n";
$t->checkEqual($csv,$expected); 
[0.026 ms]
'id,price 1,"2,5 €" 2,"3,45 €" '
Ok
offset 1523 $data = [
  [
'A'3],
  [
'B'6],
  [
'A'14],
];
$newData TableArray::create($data)
  ->
offset(1)  //remove 1.row from table-Object
  
->fetchAll();
$expected = [
  
//['A', 3],
  
['B'6],
  [
'A'14],
];
$t->checkEqual($newData$expected); 
[0.017 ms]
array ( 0 => array ( 0 => 'B', 1 => 6, ), 1 => array ( 0 => 'A', 1 => 14, ), )
Ok
limit 1539 $data = [
  [
'A'3],
  [
'B'6],
  [
'A'14],
];
$newData TableArray::create($data)
  ->
limit(2//remove 3.row from table-Object
  
->fetchAll();
$expected = [
  [
'A'3],
  [
'B'6],
  
//['A', 14],
];
$t->checkEqual($newData$expected); 
[0.014 ms]
array ( 0 => array ( 0 => 'A', 1 => 3, ), 1 => array ( 0 => 'B', 1 => 6, ), )
Ok
limit from end 1555 $data = [
  [
'A'3],
  [
'B'6],
  [
'A'14],
];
$newData TableArray::create($data)
  ->
limit(-1//get last row
  
->fetchAll();
$expected = [
  
//['A', 3],
  //['B', 6],
  
['A'14],
];
$t->checkEqual($newData$expected); 
[0.011 ms]
array ( 0 => array ( 0 => 'A', 1 => 14, ), )
Ok
limit with fetch 1571 $data = [
  [
'A'3],
  [
'B'6],
  [
'A'14],
];
$newData TableArray::create($data)
  ->
fetchLimit(2);
$expected = [
  [
'A'3],
  [
'B'6],
];
$t->checkEqual($newData$expected); 
[0.006 ms]
array ( 0 => array ( 0 => 'A', 1 => 3, ), 1 => array ( 0 => 'B', 1 => 6, ), )
Ok
limit with fetch and start 1585 $data = [
  [
'A'3],
  [
'B'6],
  [
'C'14],
];
$newData TableArray::create($data)
  ->
fetchLimit(2,1);  //Limit 2, Start 1
$expected = [
  [
'B'6],
  [
'C'14],
];
$t->checkEqual($newData$expected); 
[0.016 ms]
array ( 0 => array ( 0 => 'B', 1 => 6, ), 1 => array ( 0 => 'C', 1 => 14, ), )
Ok
limit with fetch, start and keep keys 1599 $data = [
  
=> ['A'3],
  
=> ['B'6],
  
=> ['C'14],
];
$newData TableArray::create($data)
  ->
fetchLimit(2,1,true);  //Limit 2, Start 1, keep keys
$expected = [
 
=> ['B'6],
 
=> ['C'14],
];
$t->checkEqual($newData$expected); 
[0.005 ms]
array ( 1 => array ( 0 => 'B', 1 => 6, ), 2 => array ( 0 => 'C', 1 => 14, ), )
Ok
limit with fetch from end 1613 $data = [
  [
'A'3],
  [
'B'6],
  [
'A'14],
];
$newData TableArray::create($data)
  ->
fetchLimitFromEnd(1);  //get last
$expected = [
  [
'A'14]
];
$t->checkEqual($newData$expected); 
[0.006 ms]
array ( 0 => array ( 0 => 'A', 1 => 14, ), )
Ok
offset + limit 1626 $data = [
  [
'A'3],
  [
'B'6],
  [
'A'14],
];
$newData TableArray::create($data)
  ->
offset(1)
  ->
limit(1)
  ->
fetchAll();
$expected = [
  
//['A', 3],
  
['B'6],
  
//['A', 14],
];
$t->checkEqual($newData$expected); 
[0.005 ms]
array ( 0 => array ( 0 => 'B', 1 => 6, ), )
Ok
pivot 1644 $data = [
[
'group' => 1'case' => 1'value' => 11],
[
'group' => 1'case' => 2'value' => 22],
];
$newData TableArray::create($data)
  ->
pivot('group','value','case')
  ->
fetchAll();
$expected = [
  
=> ['group' => 1'value.1' => 11'value.2' => 22]
];
$t->checkEqual($newData$expected); 
[0.011 ms]
array ( 1 => array ( 'group' => 1, 'value.1' => 11, 'value.2' => 22, ), )
Ok
pivot and select 1658 $data = [
[
'group' => 1'case' => 1'value' => 11],
[
'group' => 1'case' => 2'value' => 22],
[
'group' => 1'case' => 3'value' => 33],
];
$newData TableArray::create($data)
  ->
pivot('group','value','case')
  ->
select('value.1 as v1, value.3 as v3')
  ->
fetchAll();
$expected = [
  
=> ['v1' => 11'v3' => 33]
];
$t->checkEqual($newData$expected); 
[0.039 ms]
array ( 1 => array ( 'v1' => 11, 'v3' => 33, ), )
Ok
merge 2 arrays with same table structure 1674 $data1 = [
  [
'id' => 1'name' => 'name1''refId' => 1],
  [
'id' => 2'name' => 'name2''refId' => 2],
];

$data2 = [
  [
'id' => 3'name' => 'name3''refId' => 3],
];
$newData TableArray::create($data1)
  ->
merge($data2)
  ->
fetchAll()
;
$expected = [
  [
'id' => 1'name' => 'name1''refId' => 1],
  [
'id' => 2'name' => 'name2''refId' => 2],
  [
'id' => 3'name' => 'name3''refId' => 3],
];
$t->checkEqual($newData$expected); 
[0.015 ms]
array ( 0 => array ( 'id' => 1, 'name' => 'name1', 'refId' => 1, ), 1 => array ( ..
Ok
merge 2 arrays with different table structure 1694 $data1 = [
  [
'id' => 1'name' => 'name1'],
  [
'id' => 2'name' => 'name2'],
];

$data2 = [
  [
'id' => 1'refId' => 1],
];
$newData TableArray::create($data1)
  ->
merge($data2)
  ->
fetchAll()
;
$expected = [
  [
'id' => 1'name' => 'name1''refId' => NULL],
  [
'id' => 2'name' => 'name2''refId' => NULL],
  [
'id' => 1'name' => NULL'refId' => 1],
];
$t->checkEqual($newData$expected); 
[0.010 ms]
array ( 0 => array ( 'id' => 1, 'name' => 'name1', 'refId' => NULL, ), 1 => arra ..
Ok
merge 2 arrays with string row keys 1714 $data1 = [
  
'id1' =>  ['name' => 'name1'],
  
'id2' =>  ['name' => 'name2'],
];
  
$data2 = [
  
'id1' => ['refId' => 1],
];
$newData TableArray::create($data1)
  ->
merge($data2)
  ->
fetchAll()
;
$expected = [
  
'id1' =>  ['name' => 'name1''refId' => 1],
  
'id2' =>  ['name' => 'name2''refId' => NULL],
];
$t->checkEqual($newData$expected); 
[0.017 ms]
array ( 'id1' => array ( 'name' => 'name1', 'refId' => 1, ), 'id2' => array ( 'n ..
Ok
inner Join 1734 $data=[
  [
'id' => 1'name' => 'name1''refId' => 1],
  [
'id' => 2'name' => 'name2''refId' => 2],
  [
'id' => 3'name' => 'name3''refId' => 3],
];
$ref=[
  [
'id' => 1'c' => 'ref1''d' => 'A'],
  [
'id' => 2'c' => 'ref2''d' => 'B']
];
$newData TableArray::create($data)
  ->
innerJoinOn($ref,'t2','id','refId')
  ->
fetchAll();

$expected=[
  [
'id' => 1'name' => 'name1'
    
'refId' => 1't2.c' => 'ref1''t2.d' => 'A'],
  [
'id' => 2'name' => 'name2'
    
'refId' => 2't2.c' => 'ref2''t2.d' => 'B'],
];
$t->checkEqual($newData$expected); 
[0.012 ms]
array ( 0 => array ( 'id' => 1, 'name' => 'name1', 'refId' => 1, 't2.c' => 'ref1 ..
Ok
inner Join without TableAlias 1756 $data=[
  [
'id' => 1'name' => 'name1''refId' => 1],
  [
'id' => 2'name' => 'name2''refId' => 2],
  [
'id' => 3'name' => 'name3''refId' => 3],
];
$ref=[
  [
'id' => 1'c' => 'ref1''d' => 'A'],
  [
'id' => 2'c' => 'ref2''d' => 'B']
];
$newData TableArray::create($data)
  ->
innerJoinOn($ref,'','id','refId')
  ->
fetchAll();

$expected=[
  [
'id' => 1'name' => 'name1'
    
'refId' => 1'c' => 'ref1''d' => 'A'],
  [
'id' => 2'name' => 'name2'
    
'refId' => 2'c' => 'ref2''d' => 'B'],
];
$t->checkEqual($newData$expected); 
[0.009 ms]
array ( 0 => array ( 'id' => 1, 'name' => 'name1', 'refId' => 1, 'c' => 'ref1', ..
Ok
left Join 1779 $data=[
  [
'id' => 1'name' => 'name1''refId' => 1],
  [
'id' => 2'name' => 'name2''refId' => 2],
  [
'id' => 3'name' => 'name3''refId' => 3],
];
$ref=[
  [
'id' => 1'c' => 'ref1''d' => 'A'],
  [
'id' => 2'c' => 'ref2''d' => 'B']
];
$newData TableArray::create($data)
  ->
leftJoinOn($ref,'t2','id','refId')
  ->
fetchAll();
  
$expected=[
  [
'id' => 1'name' => 'name1'
    
'refId' => 1't2.c' => 'ref1''t2.d' => 'A'],
  [
'id' => 2'name' => 'name2'
    
'refId' => 2't2.c' => 'ref2''t2.d' => 'B'],
  [
'id' => 3'name' => 'name3'
    
'refId' => 3't2.c' => null't2.d' => null],
];
$t->checkEqual($newData$expected); 
[0.019 ms]
array ( 0 => array ( 'id' => 1, 'name' => 'name1', 'refId' => 1, 't2.c' => 'ref1 ..
Ok
inner Join, select, order 1804 $data=[
  [
'id' => 1'name' => 'name1''refId' => 1],
  [
'id' => 2'name' => 'name2''refId' => 2],
  [
'id' => 3'name' => 'name3''refId' => 3],
];
$ref=[
  [
'id' => 1'c' => 'ref1''d' => 'A'],
  [
'id' => 2'c' => 'ref2''d' => 'X'],
  [
'id' => 3'c' => 'ref3''d' => 'C']
];
$newData TableArray::create($data)
  ->
innerJoinOn($ref,'t2','id','refId')
  ->
select('id, name, t2.d')
  ->
orderBy('t2.d DESC')
  ->
limit(1)
  ->
fetchAll();

$expected=[
  [
'id' => 2'name' => 'name2''t2.d' => 'X'],
];
$t->checkEqual($newData$expected); 
[0.025 ms]
array ( 0 => array ( 'id' => 2, 'name' => 'name2', 't2.d' => 'X', ), )
Ok
multiple Join 1827 //input
$data=[ 
  [
'id' => 1'name' => 'name1''refId' => 1], 
  [
'id' => 2'name' => 'name2''refId' => 2], 
]; 
$refA=[ 
  [
'id' => 1'key' => 'k1'], 
  [
'id' => 2'key' => 'k2'
]; 
$refB=[ 
  [
'id' => 'k1''name' => 'Hardware'], 
  [
'id' => 'k2''name' => 'Software'
]; 

//join and select
$tabArr_A TableArray::create($refA)
->
innerJoinOn($refB,'refb','id','key')
->
select('id,refb.name as name')
;

$newData TableArray::create($data
  ->
innerJoinOn($tabArr_A,'t2','id','refId')
  ->
select('id,t2.name as fullname')
  ->
fetchAll()
;

$expected = [
  [ 
'id' => 1'fullname' => 'Hardware'],
  [ 
'id' => 2'fullname' => 'Software'],
]; 
$t->checkEqual($newData$expected); 
[0.027 ms]
array ( 0 => array ( 'id' => 1, 'fullname' => 'Hardware', ), 1 => array ( 'id' = ..
Ok
#filter Equal: where size = large 1863 $data = [
  [
"id" => "123""sku" => "MED_BL_DRESS""size" => "medium""color" => "black"],
  [
"id" => "321""sku" => "LG_GR_DRESS""size" => "large""color" => "green"],
  [
"id" => "31321""sku" => "LG_RD_DRESS""size" => "large""color" => "red"]
];
$newData TableArray::create($data)
  ->
filterEqual('size''large')
  ->
fetchAll()
;
$expected = [
  
=> ["id" => "321""sku" => "LG_GR_DRESS""size" => "large""color" => "green"],
  
=> ["id" => "31321""sku" => "LG_RD_DRESS""size" => "large""color" => "red"]
];
$t->checkEqual($newData$expected); 
[0.018 ms]
array ( 1 => array ( 'id' => '321', 'sku' => 'LG_GR_DRESS', 'size' => 'large', ' ..
Ok
filterEqual: [size => large] 1879 $newData TableArray::create($data)
  ->
filterEqual(['size' => 'large'])
  ->
fetchAll()
;
$t->checkEqual($newData$expected); 
[0.006 ms]
array ( 1 => array ( 'id' => '321', 'sku' => 'LG_GR_DRESS', 'size' => 'large', ' ..
Ok
filterEqual: where size = large AND color = green 1886 $data = [
  [
"id" => "123""sku" => "MED_BL_DRESS""size" => "medium""color" => "black"],
  [
"id" => "321""sku" => "LG_GR_DRESS""size" => "large""color" => "green"],
  [
"id" => "31321""sku" => "LG_RD_DRESS""size" => "large""color" => "red"]
];
$newData TableArray::create($data)
  ->
filterEqual(['size' => 'large''color' => 'green'])
  ->
fetchAll()
;
$expected = [
  
=> ["id" => "321""sku" => "LG_GR_DRESS""size" => "large""color" => "green"],
];
$t->checkEqual($newData$expected); 
[0.006 ms]
array ( 1 => array ( 'id' => '321', 'sku' => 'LG_GR_DRESS', 'size' => 'large', ' ..
Ok
filter Like In 1902 $data=[
  [
'id' => 1'art' => '123457''feature' => 'TV OLED UHD WLAN 65 Zoll'],
  [
'id' => 2'art' => '123456''feature' => 'TV OLED UHD WLAN 55 Zoll'],
  [
'id' => 3'art' => '653456''feature' => 'TV LED HD 55 Zoll'],
];
$newData TableArray::create($data)
  ->
filterLikeIn('feature','wlan,65')
  ->
fetchAll();
$expected=[
  [
'id' => 1'art' => '123457''feature' => 'TV OLED UHD WLAN 65 Zoll'],
  [
'id' => 2'art' => '123456''feature' => 'TV OLED UHD WLAN 55 Zoll'],
]; 
$t->checkEqual($newData$expected); 
[0.008 ms]
array ( 0 => array ( 'id' => 1, 'art' => '123457', 'feature' => 'TV OLED UHD WLA ..
Ok
filter Like In (Integer field) 1917 $data=[
  [
'id' => 1'art' => 123457'feature' => 'TV OLED UHD WLAN 65 Zoll'],
  [
'id' => 2'art' => 123456'feature' => 'TV OLED UHD WLAN 55 Zoll'],
  [
'id' => 3'art' => 653456'feature' => 'TV LED HD 55 Zoll'],
];
$newData TableArray::create($data)
  ->
filterLikeIn('art','6,7,123456,8')
  ->
fetchAll();
$expected=[
  [
'id' => 2'art' => 123456'feature' => 'TV OLED UHD WLAN 55 Zoll'],
]; 
$t->checkEqual($newData$expected); 
[0.008 ms]
array ( 0 => array ( 'id' => 2, 'art' => 123456, 'feature' => 'TV OLED UHD WLAN ..
Ok
filter Like All 1931 $data=[
  [
'id' => 1'art' => '123457''feature' => 'TV OLED UHD WLAN 65 Zoll'],
  [
'id' => 2'art' => '123456''feature' => 'TV OLED UHD WLAN 55 Zoll'],
  [
'id' => 3'art' => '653456''feature' => 'TV LED HD 55 Zoll'],
];
$newData TableArray::create($data)
  ->
filterLikeAll('feature','wlan,65')
  ->
fetchAll();
$expected=[
  [
'id' => 1'art' => '123457''feature' => 'TV OLED UHD WLAN 65 Zoll'],
]; 
$t->checkEqual($newData$expected); 
[0.022 ms]
array ( 0 => array ( 'id' => 1, 'art' => '123457', 'feature' => 'TV OLED UHD WLA ..
Ok
filterUnique: remove duplicate rows 1945 $data=[
  [
'id' => 1'city' => 'New York''street' => 'Fifth Avenue'],
  [
'id' => 1'city' => 'New York''street' => 'Fifth Avenue'],
  [
'id' => 2'city' => 'New York''street' => 'Fifth Avenue'],
  [
'id' => 1'city' => 'New York''street' => 'Fifth Avenue'],
];
$newData TableArray::create($data)
  ->
filterUnique()
  ->
fetchAll()
;
$expected=[
  [
'id' => 1'city' => 'New York''street' => 'Fifth Avenue'],
  [
'id' => 2'city' => 'New York''street' => 'Fifth Avenue'],
]; 
$t->checkEqual($newData$expected); 
[0.007 ms]
array ( 0 => array ( 'id' => 1, 'city' => 'New York', 'street' => 'Fifth Avenue' ..
Ok
filterUnique: remove dublicate city and street 1962 $newData TableArray::create($data)
  ->
filterUnique(['city','street'])
  ->
fetchAll()
;
$expected=[
  [
'id' => 1'city' => 'New York''street' => 'Fifth Avenue'],
]; 
$t->checkEqual($newData$expected); 
[0.009 ms]
array ( 0 => array ( 'id' => 1, 'city' => 'New York', 'street' => 'Fifth Avenue' ..
Ok
filterUnique argument incorrect -> exception 1972 $closure = function(){
  
TableArray::create()->filterUnique(['unknown']);
};
$t->checkException($closure,'InvalidArgumentException'); 
[0.001 ms]
'Exception: InvalidArgumentException'
Ok
#Aggregate filter MAX: without group 1978 $data = [ 
  [
'id' => "1",'group' => 1'value' => 2], 
  [
'id' => "2",'group' => 2'value' => 4],
  [
'id' => "3",'group' => 1'value' => 1], 
  [
'id' => "4",'group' => 2'value' => 6],
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['value' => 'MAX'])
  ->
fetchAll();
$expected = [//id + group from row with MAX 
  
['id' => "4",'group' => 2'value' => 6],
];
$t->checkEqual($newData$expected); 
[0.039 ms]
array ( 0 => array ( 'id' => '4', 'group' => 2, 'value' => 6, ), )
Ok
filter MIN without group 1993 $data = [
  [
'id' => "1",'group' => 1'value' => 2], 
  [
'id' => "2",'group' => 2'value' => 4],
  [
'id' => "3",'group' => 1'value' => 1], 
  [
'id' => "4",'group' => 2'value' => 6],
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['value' => 'MIN'])
  ->
fetchAll();
$expected = [ //id + group from row with MIN
  
['id' => "3",'group' => 1'value' => 1], 
];
$t->checkEqual($newData$expected); 
[0.010 ms]
array ( 0 => array ( 'id' => '3', 'group' => 1, 'value' => 1, ), )
Ok
filter SUM without group 2008 $data = [ 
  [
'id' => "1",'group' => 1'value' => 2], 
  [
'id' => "2",'group' => 2'value' => 4],
  [
'id' => "3",'group' => 1'value' => 1], 
  [
'id' => "4",'group' => 2'value' => 6],
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['value' => 'SUM'])
  ->
fetchAll();
$expected = [ //id + group from first row 
  
['id' => "1",'group' => 1'value' => 13], 
];
$t->checkEqual($newData$expected); 
[0.009 ms]
array ( 0 => array ( 'id' => '1', 'group' => 1, 'value' => 13, ), )
Ok
filter AVG without group 2023 $data = [ 
  [
'id' => "1",'group' => 1'value' => 2], 
  [
'id' => "2",'group' => 2'value' => 4],
  [
'id' => "3",'group' => 1'value' => 1], 
  [
'id' => "4",'group' => 2'value' => 6],
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['value' => 'AVG'])
  ->
fetchAll();
$expected = [ //id + group from first row 
  
['id' => "1",'group' => 1'value' => 13/4], 
];
$t->checkEqual($newData$expected); 
[0.015 ms]
array ( 0 => array ( 'id' => '1', 'group' => 1, 'value' => 3.25, ), )
Ok
filter COUNT without group 2038 $data = [ 
  [
'id' => "1",'group' => 1'value' => 2], 
  [
'id' => "2",'group' => 2'value' => 4],
  [
'id' => "3",'group' => 1'value' => 1], 
  [
'id' => "4",'group' => 2'value' => 6],
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['value' => 'COUNT'])
  ->
fetchAll();
$expected = [ //id + group from first row 
  
['id' => "1",'group' => 1'value' => 4], 
];
$t->checkEqual($newData$expected); 
[0.008 ms]
array ( 0 => array ( 'id' => '1', 'group' => 1, 'value' => 4, ), )
Ok
filter CONCAT without group 2053 $data = [ 
  [
'id' => "1",'group' => 1'value' => 2], 
  [
'id' => "2",'group' => 2'value' => 4],
  [
'id' => "3",'group' => 1'value' => 1], 
  [
'id' => "4",'group' => 2'value' => 6],
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['value' => 'CONCAT'])
  ->
fetchAll();
$expected = [ //id + group from first row 
  
['id' => "1",'group' => 1'value' => '2,4,1,6'], 
];
$t->checkEqual($newData$expected); 
[0.021 ms]
array ( 0 => array ( 'id' => '1', 'group' => 1, 'value' => '2,4,1,6', ), )
Ok
filter aggregate JSON with 3 groups 2068 $data = [
  [
'id' => 1,'hersteller_id' => "1",'model' => "A3",'farbe' => "schwarz"],
  [
'id' => 2,'hersteller_id' => "1",'model' => "A3",'farbe' => "rot"],
  [
'id' => 3,'hersteller_id' => "2",'model' => "318",'farbe' => "blau"],
  [
'id' => 4,'hersteller_id' => "1",'model' => "A3"'farbe' => "schwarz"]
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['id' => 'JSON'],['hersteller_id','model','farbe'],",")
  ->
fetchAll()
;
$expected = [
  [
'id' => '[1,4]','hersteller_id' => "1",'model' => "A3",'farbe' => "schwarz"],
  [
'id' => '[2]','hersteller_id' => "1",'model' => "A3",'farbe' => "rot"],
  [
'id' => '[3]','hersteller_id' => "2",'model' => "318",'farbe' => "blau"],
];
$t->checkEqual($newData$expected); 
[0.022 ms]
array ( 0 => array ( 'id' => '[1,4]', 'hersteller_id' => '1', 'model' => 'A3', ' ..
Ok
filter aggregate in ARRAY with 3 groups 2086 $data = [
  [
'id' => 1,'hersteller_id' => "1",'model' => "A3",'farbe' => "schwarz"],
  [
'id' => 2,'hersteller_id' => "1",'model' => "A3",'farbe' => "rot"],
  [
'id' => 3,'hersteller_id' => "2",'model' => "318",'farbe' => "blau"],
  [
'id' => 4,'hersteller_id' => "1",'model' => "A3"'farbe' => "schwarz"]
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['id' => 'ARRAY'],['hersteller_id','model','farbe'],",")
  ->
fetchAll()
;
$expected = [
  [
'id' => [1,4],'hersteller_id' => "1",'model' => "A3",'farbe' => "schwarz"],
  [
'id' => [2],'hersteller_id' => "1",'model' => "A3",'farbe' => "rot"],
  [
'id' => [3],'hersteller_id' => "2",'model' => "318",'farbe' => "blau"],
];
$t->checkEqual($newData$expected); 
[0.014 ms]
array ( 0 => array ( 'id' => array ( 0 => 1, 1 => 4, ), 'hersteller_id' => '1', ..
Ok
filter MIN + MAX without group 2104 $data = [ 
  [
'id' => "1",'group' => 1'value' => 2], 
  [
'id' => "2",'group' => 2'value' => 4],
  [
'id' => "3",'group' => 1'value' => 1], 
  [
'id' => "4",'group' => 2'value' => 6],
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['group' => 'MAX','value' => 'MIN'])
  ->
fetchAll();
$expected = [ //id + group from value = MIN 
  
['id' => "3",'group' => 2'value' => 1], 
];
$t->checkEqual($newData$expected); 
[0.013 ms]
array ( 0 => array ( 'id' => '3', 'group' => 2, 'value' => 1, ), )
Ok
filter MAX: with group 2119 $data = [ 
  [
'id' => "1",'group' => 1'value' => 2], 
  [
'id' => "2",'group' => 2'value' => 4],
  [
'id' => "3",'group' => 1'value' => 1], 
  [
'id' => "4",'group' => 2'value' => 6],
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['value' => 'max'],['group'])
  ->
fetchAll();
$expected = [ 
  [
'id' => "1",'group' => 1'value' => 2], 
  [
'id' => "4",'group' => 2'value' => 6],
];
$t->checkEqual($newData$expected); 
[0.021 ms]
array ( 0 => array ( 'id' => '1', 'group' => 1, 'value' => 2, ), 1 => array ( 'i ..
Ok
filter MAX + SUM: with group 2135 $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'])
  ->
fetchAll();
$expected = [ 
  [
'id' => "1",'group' => 1'value' => 2'value2' => 2.5], 
  [
'id' => "4",'group' => 2'value' => 6'value2' => 7.5],
];
$t->checkEqual($newData$expected); 
[0.017 ms]
array ( 0 => array ( 'id' => '1', 'group' => 1, 'value' => 2, 'value2' => 2.5, ) ..
Ok
filter Max: with 2 groups 2151 $data = [ 
  [
'id' => "1",'group' => 1'group2' => 'A''value' => 2], 
  [
'id' => "2",'group' => 2'group2' => 'A''value' => 4],
  [
'id' => "3",'group' => 1'group2' => 'A''value' => 1], 
  [
'id' => "4",'group' => 2'group2' => 'A''value' => 6],
  [
'id' => "5",'group' => 1'group2' => 'B''value' => 1], 
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['value' => 'max'],['group','group2'])
  ->
fetchAll();
$expected = [ 
  [
'id' => "1",'group' => 1'group2' => 'A''value' => 2], 
  [
'id' => "4",'group' => 2'group2' => 'A''value' => 6],
  [
'id' => "5",'group' => 1'group2' => 'B''value' => 1], 
];
$t->checkEqual($newData$expected); 
[0.014 ms]
array ( 0 => array ( 'id' => '1', 'group' => 1, 'group2' => 'A', 'value' => 2, ) ..
Ok
group_max argument incorrect -> exception 2169 $closure = function(){
  
TableArray::create([[]])
    ->
filterGroupAggregate(['value' => 'max'],['group11'])
  ;
};
$t->checkException($closure,'InvalidArgumentException'); 
[0.000 ms]
'Exception: InvalidArgumentException'
Ok
filterGroup Count 2177 $data = [ 
  [
'id' => "1",'group' => 1'value' => 2], 
  [
'id' => "2",'group' => 2'value' => 4],
  [
'id' => "3",'group' => 1'value' => 1], 
  [
'id' => "4",'group' => 1'value' => 6],
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['value' => 'COUNT'],['group'])
  ->
fetchAll();
$expected = [ 
  [
'id' => "1",'group' => 1'value' => 3],
  [
'id' => "2",'group' => 2'value' => 1],
];
$t->checkEqual($newData$expected); 
[0.020 ms]
array ( 0 => array ( 'id' => '1', 'group' => 1, 'value' => 3, ), 1 => array ( 'i ..
Ok
filterGroup Concat 2193 $data = [ 
  [
'id' => "1",'group' => 1'value' => 2], 
  [
'id' => "2",'group' => 2'value' => 4],
  [
'id' => "3",'group' => 1'value' => 1], 
  [
'id' => "4",'group' => 1'value' => 6],
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['value' => 'CONCAT'],['group'],",")
  ->
fetchAll();
$expected = [ 
  [
'id' => "1",'group' => 1'value' => '2,1,6'],
  [
'id' => "2",'group' => 2'value' => '4'],
];
$t->checkEqual($newData$expected); 
[0.011 ms]
array ( 0 => array ( 'id' => '1', 'group' => 1, 'value' => '2,1,6', ), 1 => arra ..
Ok
filterGroup Concat with 2 groups and order 2209 $data = [ 
  [
'id' => "1",'firstname' => 'Fritz''surname' => "Schulz"'tel' => '08505678'], 
  [
'id' => "2",'firstname' => 'Anna''surname' => "Schulz"'tel' => '08505678'], 
  [
'id' => "3",'firstname' => 'Fritz''surname' => "Schulz"'tel' => '0986644'], 
  [
'id' => "4",'firstname' => 'Fritz''surname' => "Meier"'tel' => '0338505678'], 
];
$newData TableArray::create($data)
  ->
filterGroupAggregate(['tel' => 'CONCAT'],['surname','firstname'],",")
  ->
orderBy("surname,firstname")
  ->
fetchAll()
;
$expected = [ 
  [
'id' => "4",'firstname' => "Fritz",'surname' => "Meier",'tel' => "0338505678"],
  [
'id' => "2",'firstname' => "Anna",'surname' => "Schulz",'tel' => "08505678"],
  [
'id' => "1",'firstname' => "Fritz",'surname' => "Schulz"'tel' => "08505678,0986644"],
];
$t->checkEqual($newData$expected); 
[0.027 ms]
array ( 0 => array ( 'id' => '4', 'firstname' => 'Fritz', 'surname' => 'Meier', ..
Ok
filter: remove all rows with a null value 2228 $data=[ 
  [
'id' => 3'art' => null'v' => 9],  
  [
'id' => 4'art' => 56'v' => ], 
  
];
$newData TableArray::create($data)
  ->
filter()
  ->
fetchAll();
$expected=[
  [
'id' => 4'art' => 56'v' => ], 
];
$t->checkEqual($newData$expected); 
[0.007 ms]
array ( 0 => array ( 'id' => 4, 'art' => 56, 'v' => 2, ), )
Ok
filter function: all rows with art * V > 100 2242 $data=[ 
  [
'id' => 1'art' => 12'v' => 7], 
  [
'id' => 2'art' => 56'v' => ],
  [
'id' => 3'art' => null'v' => 9],  
  [
'id' => 4'art' => 34'v' => ], 
];
$newData TableArray::create($data)
  ->
filter(function($row){return ($row['art'] * $row['v']) > 100;})
  ->
fetchAll();
$expected=[
  [
'id' => 2'art' => 56'v' => ], 
];
$t->checkEqual($newData$expected); 
[0.020 ms]
array ( 0 => array ( 'id' => 2, 'art' => 56, 'v' => 2, ), )
Ok
walk: modify rows 2258 $data=[ 
  [
'id' => 1'art' => 12'v' => 7], 
  [
'id' => 2'art' => 56'v' => ],
];

$callback = function($row$key$userData){
  
$row['v'] += $userData;
  return 
$row;
};
$userData 3;

$newData TableArray::create($data)
  ->
walk($callback$userData)
  ->
fetchAll()
;
$expected = [
  [
'id' => 1'art' => 12'v' => 10], 
  [
'id' => 2'art' => 56'v' => ],
];
$t->checkEqual($newData$expected); 
[0.007 ms]
array ( 0 => array ( 'id' => 1, 'art' => 12, 'v' => 10, ), 1 => array ( 'id' => ..
Ok
transpose array 2281 $data=['id' => [1,2], 'art' => [12,56], 'v' => [7,2]];

$newData TableArray::create($data)
->
transpose()
->
fetchAll()
;

$expected = [
  [
'id' => 1'art' => 12'v' => 7], 
  [
'id' => 2'art' => 56'v' => ],
];
$t->checkEqual($newData$expected); 
[0.006 ms]
array ( 0 => array ( 'id' => 1, 'art' => 12, 'v' => 7, ), 1 => array ( 'id' => 2 ..
Ok
addFlatKeys: add flatten cols from array-fields 2295 $data = [
  [
'id' => 1'@attributes' => ['currency' => "USD",'rate' => "1.1370"]],
  [
'id' => 2'@attributes' => ['currency' => "JPY",'rate' => "1.28"]],
];
$newData TableArray::create($data)
  ->
addFlatKeys()
  ->
fetchAll();
$expected = [
  [
'id' => 1'@attributes' => ['currency' => "USD",'rate' => "1.1370"],
    
'@attributes.currency' => "USD",'@attributes.rate' => "1.1370"],
  [
'id' => 2'@attributes' => ['currency' => "JPY",'rate' => "1.28"],
    
'@attributes.currency' => "JPY",'@attributes.rate' => "1.28"],
];
$t->checkEqual($newData$expected); 
[0.012 ms]
array ( 0 => array ( 'id' => 1, '@attributes' => array ( 'currency' => 'USD', 'r ..
Ok
addFlatKeys: sort by @attributes->currency 2311 $data = [
  [
'id' => 1'@attributes' => ['currency' => "USD",'rate' => "1.1370"]],
  [
'id' => 2'@attributes' => ['currency' => "JPY",'rate' => "1.28"]],
];
$newData TableArray::create($data)
  ->
addFlatKeys()
  ->
orderBy('@attributes.currency')
  ->
select('id,@attributes'
  ->
fetchAll();
$expected = [
  [
'id' => 2'@attributes' => ['currency' => "JPY",'rate' => "1.28"]],
  [
'id' => 1'@attributes' => ['currency' => "USD",'rate' => "1.1370"]],
];
$t->checkEqual($newData$expected); 
[0.032 ms]
array ( 0 => array ( 'id' => 2, '@attributes' => array ( 'currency' => 'JPY', 'r ..
Ok
check if data is a table-Array 2328 $data = [ //is a table array
  
[1,2,3],
  [
4,5,6]
];  
$result TableArray::check($data);
$t->checkEqual($resulttrue); 
[0.003 ms]
true
Ok
check if data is a table-Array 2336 $data = [ //is not a table array
  
[1,2,3],
  [
4,5]
];  
$result TableArray::check($data);
$t->checkEqual($resultfalse); 
[0.001 ms]
false
Ok
check if data is a table-Array 2344 $data = [1,2,3]; //not a table array
$result TableArray::check($data);
$t->checkEqual($resultfalse); 
[0.001 ms]
false
Ok
check if data is a table-Array 2349 $data=[ //is a table array
  
['id' => 1'v' => 7], 
  [
'id' => 2'v' => ],
];
$result TableArray::check($data);
$t->checkEqual($resulttrue); 
[0.001 ms]
true
Ok
check if data is a table-Array 2357 $data=[ //is not a table array
  
['id' => 1'v' => 7], 
  [
'id' => 2'X' => ],  //different keys
];
$result TableArray::check($data);
$t->checkEqual($resultfalse); 
[0.001 ms]
false
Ok
get Keys from all rows 2366 $data=[ //is not a table array
  
['id' => 1'v' => 7], 
  [
'id' => 2'X' => ],  //different keys
];
$result TableArray::allRowKeys($data);
$expected = ['id','v','X'];
$t->checkEqual($result$expected); 
[0.002 ms]
array ( 0 => 'id', 1 => 'v', 2 => 'X', )
Ok
get Keys from all rows 2375 $data = [
  [
1,2,3], 
  [
11"a" => "val_a"],
'c' =>  [12,'b' => 'val_b''a' => 'val2_a'],
  [
=> 22]
];
$result TableArray::allRowKeys($data);
$expected = [0,1,2,'a','b'];
$t->checkEqual($result$expected); 
[0.002 ms]
array ( 0 => 0, 1 => 1, 2 => 2, 3 => 'a', 4 => 'b', )
Ok
get Keys from 1 dim array -> false 2386 $data = [1,2,3];
$result TableArray::allRowKeys($data);
$t->checkEqual($resultfalse); 
[0.001 ms]
false
Ok
rectify to table structure 2392 $data = [
  [
1,2,3], 
  [
11"a" => "val_a"],
'c' =>  [12,'b' => 'val_b''a' => 'val2_a'],
  [
=> 22]
];
$result TableArray::create($data)
  ->
rectify()
  ->
fetchAll()
;
$expected = [
        [ 
=> 1=> 2=> 3'a' => NULL'b' => NULL],
        [ 
=> 11=> NULL=> NULL'a' => "val_a"'b' => NULL],
'c' =>  [ => 12=> NULL=> NULL'a' => "val2_a"'b' => "val_b"],
        [ 
=> NULL=> NULL=> 22'a' => NULL'b' => NULL]
];
$t->checkEqual($result$expected); 
[0.011 ms]
array ( 0 => array ( 0 => 1, 1 => 2, 2 => 3, 'a' => NULL, 'b' => NULL, ), 1 => a ..
Ok
debug print 2415 $data = [ //is a table array
  
[11,12],
  [
21,22]
];  
TableArray::create($data)
  ->
dprint('default limit 100')
;
$t->checkOutput('default limit 100,11,22'); 
[0.011 ms]

// default limit 100
$data = array (
  0 => 
  array (
    0 => 11,
    1 => 12,
  ),
  1 => 
  array (
    0 => 21,
    1 => 22,
  ),
);
Ok
debug print limit 1 2425 $data = [ //is a table array
  
[11,12],
  [
21,22]
];  
TableArray::create($data)
  ->
dprint('limit 1',1)
;
$t->checkOutput('limit 1,11,12'); 
[0.023 ms]

// limit 1
$data = array (
  0 => 
  array (
    0 => 11,
    1 => 12,
  ),
);
Ok
create big Integer field 2439 //create data
$data =[];
//$len = 1000;
for($i=1$i <= $len $i++){
  
$data[] = ['id' => $i'no' => $i+10];
}
$t->checkEqual(count($data), $len); 
[0.276 ms]
1000
Ok
like in big Integer field 2448 $newData TableArray::create($data)
  ->
filterLikeIn('no','6,7,356,956')
  ->
fetchAll();
$expected=[
  [
'id' => 346'no' => 356],
  [
'id' => 946'no' => 956],
];
$t->checkEqual($newData$expected); 
[0.389 ms]
array ( 0 => array ( 'id' => 346, 'no' => 356, ), 1 => array ( 'id' => 946, 'no' ..
Ok
create SQLite Table 2458 $db = new PDO(
  
"sqlite::memory:",
  
NULL,
  
NULL,
  [
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]
);
$sql "CREATE TABLE tab (id INTEGER PRIMARY KEY  NOT NULL , no INTEGER)";
$r $db ->exec($sql);
$sql "INSERT INTO tab (id, no) VALUES ";
for(
$i=1$i <= $len$i++){
 
$sql .= "(".$i.",".($i+10)."),";
}
$sql rtrim($sql,",");
$count $db->exec($sql);
$t->checkEqual($count$len); 
[19.3 ms]
1000
Ok
select SQLite Table 2475 $sql "SELECT * from tab WHERE no IN(6,7,356,956)";
$stmt $db->query($sql);
$result $stmt->fetchAll(PDO::FETCH_ASSOC);
$expected=[
  [
'id' => '346''no' => '356'],
  [
'id' => '946''no' => '956'],
];
$t->checkEqual($result$expected); 
[0.203 ms]
array ( 0 => array ( 'id' => '346', 'no' => '356', ), 1 => array ( 'id' => '946' ..
Ok
select SQLite Table and FETCH_KEY_PAIR 2485 $sql "SELECT * from tab WHERE no IN(6,7,356,956)";
$stmt $db->query($sql);
$result $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
$expected=[ 346 => '356'946 => '956'];
$t->checkEqual($result$expected); 
[0.155 ms]
array ( 346 => '356', 946 => '956', )
Ok
Create from PDO Statement 2492 $sql "SELECT * from tab WHERE no IN(6,7,356,956)";
$stmt $db->query($sql);
$tabArr TableArray::create($stmt);
$result $tabArr->fetchAll();
$expected=[
  [
'id' => '346''no' => '356'],
  [
'id' => '946''no' => '956'],
];
$t->checkEqual($result$expected); 
[0.176 ms]
array ( 0 => array ( 'id' => '346', 'no' => '356', ), 1 => array ( 'id' => '946' ..
Ok
Multiple fetch 2503 $result $tabArr->fetchKeyValue('id','no');
$expected=[ 346 => '356'946 => '956'];
$t->checkEqual($result$expected); 
[0.002 ms]
array ( 346 => '356', 946 => '956', )
Ok
create Testdata (20.000 rows) 2509 $data =[];
$id 1;
$group2 'A';
for( 
$dt=date_create('today - 70 days'); $dt date_create('today'); $dt->modify('+15 Minutes')){
   
$strDate $dt->format("Y-m-d H:i:s");
   
$data[] = ['id' => $id++, 'date' => $strDate'group' => 1'group2' => $group2];
   
$data[] = ['id' => $id++, 'date' => $strDate'group' => 2'group2' => $group2];
   
$data[] = ['id' => $id++, 'date' => $strDate'group' => 3'group2' => $group2];
   
$group2 = ($group2 == 'A') ? 'B' 'A';
}
$count count($data);
$t->check($count$count 0); 
[33.4 ms]
20148
Ok
group max 2523 $newData TableArray::create($data)
  ->
filterGroupAggregate(['date' => 'MAX'],['group','group2'])
  ->
fetchAll();
$t->check($newDatacount($newData) == 6); 
[20.2 ms]
array ( 0 => array ( 'id' => 20143, 'date' => '2022-05-18 23:30:00', 'group' => ..
Ok
countable object TableArray 2530 $data=[ //is a table array
  
['id' => 1'v' => 7], 
  [
'id' => 2'v' => ],
];
$result count(new TableArray($data));
$t->checkEqual($result2); 
[0.634 ms]
2
Ok
check function ungroup 2538 $groupedArray = [
  
"A" => [
    [
'id' => 1'val' => 21],
    [
'id' => 3'val' => 32],
  ],
  
"B" => [
    [
'id' => 2'val' => 28],
    [
'id' => 4'val' => 44],
  ],
];
$data TableArray::unGroup($groupedArray,['type']);
$expected = [
  [
'type' => "A"'id' => 1'val' => 21],
  [
'type' => "A"'id' => 3'val' => 32],
  [
'type' => "B"'id' => 2'val' => 28],
  [
'type' => "B"'id' => 4'val' => 44],
];
$t->checkEqual($data$expected); 
[0.008 ms]
array ( 0 => array ( 'type' => 'A', 'id' => 1, 'val' => 21, ), 1 => array ( 'typ ..
Ok
check wildcardMatch with ? 2558 /*
 * checks for internal methods and functions
 */
$string 'a.b1.b2.c';
$pattern 'a.?.?.c';
$match TableArray::wildcardMatch($pattern$string);
$t->checkEqual($match,true); 
[0.045 ms]
true
Ok
check wildcardMatch with ? 2567 $string 'a.b1.b2.c';
$pattern 'a.b.?.c';
$match TableArray::wildcardMatch($pattern$string);
$t->checkEqual($match,false); 
[0.014 ms]
false
Ok
check wildcardMatch with ? 2573 $string 'a.bbx.b2.c';
$pattern 'a.b?.?.c';
$match TableArray::wildcardMatch($pattern$string);
$t->checkEqual($match,true); 
[0.018 ms]
true
Ok
check wildcardMatch with * and ? 2579 $string 'a.b1.b2.b3.c.d';
$pattern 'a.*.c.?';  
$match TableArray::wildcardMatch($pattern$string);
$t->checkEqual($match,true); 
[0.019 ms]
true
Ok
check wildcardMatch with * and ? 2585 $string 'a.b1.b2.b3.c.d';
$pattern 'a.*.d.?';  
$match TableArray::wildcardMatch($pattern$string);
$t->checkEqual($match,false); 
[0.014 ms]
false
Ok