PHP code example of cloned / luckybox

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

    

cloned / luckybox example snippets



use LuckyBox\LuckyBox;
use LuckyBox\Card\IdCard;

// Items
$items = array(
    1 => array('name' => 'Coin',     'rate' => 60), // 60%
    2 => array('name' => 'Mushroom', 'rate' => 35), // 35%
    3 => array('name' => 'Star',     'rate' => 5),  //  5%
);

// Setup
$luckyBox = new LuckyBox();

foreach ($items as $id => $item) {
    $card = new IdCard();
    $card->setId($id)
         ->setRate($item['rate']);

    $luckyBox->add($card);
}

// Draw
$card = $luckyBox->draw();
$item = $items[$card->getId()];

echo "You got {$item['name']}" . PHP_EOL;

$luckyBox = new LuckyBox();

// Add some cards.

$luckyBox->setConsumable(true);

while (!$luckyBox->isEmpty()) {
    $card = $luckyBox->draw();

    // Do something.
}

$card1 = new IdCard();
$card2 = new IdCard();
$card1->setRate(1023); // 10.23%
$card2->setRate(8977); // 89.77%

$luckyBox->remove($card);

$luckyBox->clear();