PHP code example of joseluisald / ab

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

    

joseluisald / ab example snippets

 php
use joseluisald\Ab\Ab;

$homepageColorTest = new Ab('homepage_color', array(
    'blue' => 1,
    'red' => 1,
));
 php
<html>
  ...
  ...
  <body style="background-color:  echo $homepageColorTest->getVariation(); 
 php
use joseluisald\Ab\Container;
use joseluisald\Ab\Ab;

// instanciar o container com um teste
$container = new Container(array(
    new Ab('homepage_color', array(
        'blue'  => 1,
        'black' => 2,
    )),
));

// adicionar outro teste
$container->add(new Ab('checkout_button_text', array(
    'Buy now'               => 4,
    'Go to checkout'        => 1,
    'Proceed to checkout'   => 1,
)));

// então você pode recuperar todos os testes
$container->getAll();

// ou um único teste, pelo seu nome
$container->get('checkout_button_text');
 php
$tests = $container; // Eu só faço isso para facilitar a leitura

foreach($tests as $test) {
    echo sprintf("Teste '%s' tem a variação %s", $test->getName(), $test->getVariation());
}

// se tiver tempo a perder conte os testes :)
echo count($tests);
 php
$test = new Ab('checkout_button_text', array(
    'Buy now!'          => 1,
    'Go to checkout!'   => 1,
));

// ou você pode configurá-los depois
$test = new Ab('checkout_button_text');

$test->setVariations(array(
    'Buy now!'          => 1,
    'Go to checkout!'   => 1,
));
 php
$test = new Ab('checkout_button_text');

$test->getVariation(); // lançará um BadMethodCallException
 php
$test = new Ab('homepage_color', array(
    'white' => 1,
    'black' => 1,
));

// definir a semente
$test->setSeed($_SESSION['seed_for_homepage_color_test']); // 326902637627;

$test->getVariation(); // black
 php
$container = new Container(new Ab('homepage_color', array(
    'black' => 1,
    'white' => 1,
)));

$container->setSeed($_SESSION['seed']); // 326902637627;);
 php
$test = new Ab('my_ab_test', array(
    'a' => 0,
    'b' => 1,
));

$test->disable();

$test->getVariation(); // retornará 'a'!
 php
$test = new Ab('example', array(1, 2), array(
    'par1' => 1,
    'par2' => new stdClass,
));

$test->set('par3', 'Whoooops!')
 php
$test->getParameters(); // retorna todos os parâmetros

$test->get('par3'); // Whoooops!

$test->get('i-dont-exist'); // NULL