PHP code example of ergebnis / data-generator

1. Go to this page and download the library: Download ergebnis/data-generator 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/ */

    

ergebnis / data-generator example snippets




declare(strict_types=1);

use Ergebnis\DataGenerator;

$generator = new DataGenerator\ConcatenatingValueGenerator(
    new DataGenerator\ValueGenerator(
        'foo',
        'bar',
        'baz',
    ),
    new DataGenerator\ValueGenerator('-'),
    new DataGenerator\ValueGenerator(
        'qux',
        'quux',
    ),
);

foreach ($generator->generate() as $value) {
    echo $value . PHP_EOL
}

// foo-qux
// foo-quux
// bar-qux
// bar-quux
// baz-qux
// baz-quux



declare(strict_types=1);

use Ergebnis\DataGenerator;

$generator = new DataGenerator\OptionalValueGenerator(
    'foo',
    'bar',
    'baz',
);

foreach ($generator->generate() as $value) {
    echo $value . PHP_EOL
}

// empty string
// foo
// bar
// baz



declare(strict_types=1);

use Ergebnis\DataGenerator;

$generator = new DataGenerator\SequentialValueGenerator(
    new DataGenerator\ValueGenerator(
        'foo',
        'bar',
        'baz',
    ),
    new DataGenerator\ValueGenerator(
      'qux',
      'quux',
    ),
);

foreach ($generator->generate() as $value) {
    echo $value . PHP_EOL
}

// foo
// bar
// baz
// qux
// quux



declare(strict_types=1);

use Ergebnis\DataGenerator;

$generator = new DataGenerator\ValueGenerator(
    'foo',
    'bar',
    'baz',
);

foreach ($generator->generate() as $value) {
    echo $value . PHP_EOL
}

// foo
// bar
// baz