I suggest you use an array to store the ballots, and then use array_shift to get the first item from the array.
I prefer using classes so I made a lottery class which allows you to "draw" the first item in the array.
If you run the code below and match the text output to the code you can see what it does.
See it live here: https://ideone.com/T8stdB
<?php
namespace Lottery;
class Lotto {
protected $lots;
public function __construct($lots = [])
{
$this->lots = $lots;
}
public function draw() {
return array_shift($this->lots);
}
}
namespace BallotGuy;
use Lottery\Lotto;
$lotto = new Lotto([313328804459,
159078851698,
226414688415,
380287830671,
301815692106,
2991355110,
]);
echo "Lotto status at this point\n";
echo "===========================================================\n";
var_dump($lotto);
echo "===========================================================\n";
echo "Drawn: " . $lotto->draw()."\n";
echo "\nLotto status at this point\n";
echo "===========================================================\n";
var_dump($lotto);
echo "===========================================================\n";
$saved = serialize($lotto);
//file_put_contents('ballots.txt',$saved);
/**
* setting to null to emulate script ending
*/
$lotto = null;
echo "Lotto set to null 'script' ends sort to speak here\n";
echo "\nLotto status at this point\n";
echo "===========================================================\n";
var_dump($lotto);
echo "===========================================================\n";
echo "Loading lotto from file\n";
//$saved = file_get_contents('ballots.txt');
$lotto = unserialize($saved);
echo "\nLotto status at this point\n";
echo "===========================================================\n";
var_dump($lotto);
echo "===========================================================\n";
echo "Drawn: ". $lotto->draw()."\n";
echo "\nLotto status at this point\n";
echo "===========================================================\n";
var_dump($lotto);
echo "===========================================================\n";
A version without the superfluos var_dumping
See it live https://ideone.com/YNKIM4
<?php
namespace Lottery;
class Lotto {
protected $lots;
public function __construct($lots = [])
{
$this->lots = $lots;
}
public function draw() {
return array_shift($this->lots);
}
}
namespace BallotGuy;
use Lottery\Lotto;
/**
* initialize lotto object
*/
$lotto = new Lotto([313328804459,
159078851698,
226414688415,
380287830671,
301815692106,
2991355110,
]);
echo "Drawn: " . $lotto->draw()."\n";
echo "Writing lotto to file. Ending script(j/k)\n";
$saved = serialize($lotto);
file_put_contents('ballots.txt',$saved);
/**
* setting to null to emulate script ending
*/
$lotto = null;
$saved = null;
echo "Loading lotto from file\n";
$saved = file_get_contents('ballots.txt');
$lotto = unserialize($saved);
echo "Drawn: ". $lotto->draw()."\n";
var_dump($lotto);