PHP code example of abmmhasan / game-draw
1. Go to this page and download the library: Download abmmhasan/game-draw 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/ */
abmmhasan / game-draw example snippets
$products = [
[
'item' => 'product_000_NoLuck', // Item code or Identifier
'chances' => '100000', // Item Chances
'amounts'=> [ 1 ] // Item Amounts
],
[
'item' => 'product_001',
'chances' => '1000',
'amounts' => '1.5,10.00001,1' // Weighted CSV formatted range (min,max,bias)
],
[
'item' => 'product_002',
'chances' => '500.001', // Fraction Allowed
'amounts' => [
1 => 100, // Amount chances
5 => 50, // Format: Amount => Chances
10 => 10.002, // Fraction allowed
]
],
[
'item' => 'product_003',
'chances' => '100',
'amounts' => [
1 => 100,
5 => 50,
10 => 10,
20 => 5,
]
],
[
'item' => 'product_004',
'chances' => '1',
'amounts' => [ 10, 15, 30, 50 ] // Amounts without probability
],
]
[
5 => 100,
15 => 50,
50 => 10,
80 => 5.001
]
$luckyDraw = new AbmmHasan\Draw\LuckyDraw($products);
$luckyDraw->pick()
[
'item' => 'product_000_NoLuck', // The item name
'amount' => 1 // the selected amount
]
$prizes =
[
'product_001'=>50, // Item Code/Identifier => Amount of the item
'product_002'=>5,
'product_003'=>3,
'product_004'=>2,
'product_005'=>1
];
$bucket = new GrandDraw();
// set resources
$bucket->setItems([ // set prizes
'product_001' => 10, // Item Code/Identifier => Amount of the item
'product_002' => 5,
'product_003' => 3,
'product_004' => 2,
'product_005' => 1
])->setUserListFilePath('./Sample1000.csv'); // set the CSV file location
// get the winners
$bucket->getWinners()
Array
(
[product_001] => Array
(
[0] => usr47671
[1] => usr57665
[2] => usr92400
[3] => usr7249
[4] => usr37860
[5] => usr57280
[6] => usr97204
[7] => usr82268
[8] => usr16521
[9] => usr24864
)
[product_002] => Array
(
[0] => usr50344
[1] => usr60450
[2] => usr62662
[3] => usr26976
[4] => usr56486
)
[product_003] => Array
(
[0] => usr92895
[1] => usr37642
[2] => usr85241
)
[product_004] => Array
(
[0] => usr84327
[1] => usr22985
)
[product_005] => Array
(
[0] => usr26819
)
)