PHP code example of fiedsch / data_util

1. Go to this page and download the library: Download fiedsch/data_util library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fiedsch / data_util example snippets



Fiedsch\Data\Helper;
use Fiedsch\Data\Listmanager;
use Fiedsch\Data\ArrayRecordCreator;

// use Helper::expandExpression() et al.
// use Listmanager to perform operations on lists (arrays)
// use ArrayRecordCreator to create data records
// use Helper::columnIndex() and Helper::columnName() for column name to numerical index mappings

print Helper::getExpression('a001', 'a111');
// 'a{001,111}'

Helper::expandExpression('a{001,111}');
// array('a001', 'a002', 'a003', ..., 'a099', 'a100', ..., 'a111')

print "someFunction(" . join(',', Helper::expandExpression('a{001,101}')) . ");";

Helper::expandExpression('image{00001,00099}.jpg');
// array('image00001.jpg', ..., 'image00099.jpg')

$listA = ['a','b','c'];
$listB = ['c','d','e'];
$manager = new Listmanager($listA);
$result = $manager->without($listB);   // ['a', 'b']
$result = $manager->intersect($listB); // ['c']
$result = $manager->union($listB);     // ['a','b','c','c','d','e']

$manager = new Listmanager(['a','b','c','c','b']);
$result = $manager->unique(); // ['a','b','c']

// find duplicates in a list
$list = ['a','b','a','a','c'];
$manager = new Listmanager($list);
$result = $manager->duplicates(); // ['a','a']
// $list[0] is considered unique, $list[2] and $list[3] are in the result

$creator = new ArrayRecordCreator(['foo','bar','baz']);
 // add values in arbitrary order
 $creator->foo = '1';
 $creator->baz = '2';
 $creator->bar = '3';
 $record = $creator->getRecord(); // [1, 3, 2]

 $creator->reset();
 $creator->foo = 'FOO';
 $record = $creator->getRecord(); // ['FOO', null, null]

 // create target columns 'col001' to 'col100'
 $creator = new ArrayRecordCreator(Helper::expandExpression('col{001,100}'));
 $creator->col042 = 'fourtytwo';
 // ...

Helper::columnIndex("A"); // 0
Helper::columnIndex("B"); // 1
// ...
Helper::columnIndex("AQ"); // 42

Helper::columnName(0); // "A"
Helper::columnName(1); // "B"
// ...
Helper::columnName(42); // "AQ"

['one'=>'A', 'two'=>'C', 'three'=>'X']

Helper::prependAndRemap(['one'=>'A', 'two'=>'C', 'three'=>'X'], ['four', 'five'])
// ['four'=>'A', 'five'=>'B', 'one'=>'C', 'two'=>'E', 'three'=>'Z']

Helper::moveWave('08-2023', -3); // '05-2023'
Helper::moveWave('02-2023', -3); // '11-2023'
Helper::moveWave('10-2023', +3); // '01-2024'

Helper::moveWave('09/2023', -3, '(\d{2})(\/)(\d{4})', Helper::ORDER_WAVE_FIRST); // '06/2023'
Helper::moveWave('2023/09', -3, '(\d{4})(\/)(\d{2})', Helper::ORDER_WAVE_LAST);  // '2023/06'