1. Go to this page and download the library: Download dseguy/data-combinator 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/ */
dseguy / data-combinator example snippets
use Datacombinator\Matrix;
$m = new Datacombinator\Matrix();
$m->addSet('x', [1,2,3]);
$m->addSet('y', [4,5,6]);
foreach($m as $value) {
print_r($value);
}
$m = new Datacombinator\Matrix();
// No argument for this closure, as we don't need it
$m->addLambda('x', function () { return rand(0, 10);});
// This closure takes the previously created values as input
// the range of random values is now twice as large
$m->addLambda('y', function ($value) { return rand(0, 2 * $value['x']);});
// the closure are called each time once, so this matrix as one element, with 2 closure calls
(
[x] => 4
[y] => 7
)
$m = new Matrix();
// No argument for this closure, as we don't need it
$m->addLambda('x', function () { return $this->uniqueId;});
$m->addSet('y', [5,6]);
(
[x] => 1
[y] => 5
)
(
[x] => 2
[y] => 6
)
$m = new Datacombinator\Matrix();
// No argument for this closure, as we don't need it
$a = $m->addConstant('a', 'A');
$m->addAlias('b', $a);
$m->addLambda('x', function ($r) { return $r['a'].($r['b'] ?? 'No B').($r['c'] ?? 'No C')});
$m->addConstant('c', 'C');
print_r($m->toArray());
Array
(
[0] => Array
(
[a] => A
// No B, because it is an alias
// No C, because it is defined later. It may be moved before 'x' to get access to it
[x] => ANo BNo C
[c] => C
[b] => A
)
)
$m = new Datacombinator\Matrix();
// Create all combinaisons from the list : total 8 of them
$m->addClone('x', new \stdClass);
$m->addSet('i', [1, 2]);
$generated = $m->toArray();