1. Go to this page and download the library: Download namshi/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/ */
namshi / ab example snippets
php
use Namshi\AB\Test;
$homepageColorTest = new Test('homepage_color', array(
'blue' => 1,
'red' => 1,
));
php
use Namshi\AB\Container;
use Namshi\AB\Test;
// instantiate the container with a test
$container = new Container(array(
new Test('homepage_color', array(
'blue' => 1,
'black' => 2,
)),
));
// add another test
$container->add(new Test('checkout_button_text', array(
'Buy now' => 4,
'Go to checkout' => 1,
'Proceed to checkout' => 1,
)));
// then you can retrieve all the tests
$container->getAll();
// or a single test, by its name
$container->get('checkout_button_text');
php
$tests = $container; // I only do this for readability
foreach($tests as $test) {
echo sprintf("Test '%s' has the variation %s", $test->getName(), $test->getVariation());
}
// if you have time to waste, count the tests :)
echo count($tests);
php
$test = new Test('checkout_button_text', array(
'Buy now!' => 1,
'Go to checkout!' => 1,
));
// or you can set them afterwards
$test = new Test('checkout_button_text');
$test->setVariations(array(
'Buy now!' => 1,
'Go to checkout!' => 1,
));
php
$test = new Test('checkout_button_text');
$test->getVariation(); // will throw a BadMethodCallException
php
$test = new Test('homepage_color', array(
'white' => 1,
'black' => 1,
));
// set the seed
$test->setSeed($_SESSION['seed_for_homepage_color_test']); // 326902637627;
$test->getVariation(); // black