PHP code example of krak / ab

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

    

krak / ab example snippets




use Krak\AB;

$exp = AB\Experiment::create('flow', [
    // first is the variant name, second is the ratio.
    ['standard', 80],
    ['variant', 20],
]);

$engine = AB\engine([$exp], new Logger()); // any PSR Logger will work
// The default engine is the Hashing engine

foreach (range(1, 10) as $i) {
    //
    echo $engine->activate('flow', 'id_'.$i.rand()) . PHP_EOL;
}