Ok i got it all to work, but i noticed that when i click the quick pick button, it doesnt check to see if any the numbers match the winning numbers, i think it has something to do with my foreach statement for the quick pick option.
Here's whatr i have so far:
Code: Select all
<?php
$intGrandPize = 10000000;
$intRegCount = 5;
$intMaxReg = 59;
$intMaxPB = 49;
$aryPick = array();
$intPower = 0;
$intPowerBall = rand(1,$intMaxPB);
if (isset($_POST['quickP'])){
//$intPowerBall = rand(1,$intMaxPB);
$aryAllBalls = range(1,$intMaxReg); // array of numbers 1 - 59
shuffle($aryAllBalls); // Randomize their order
$aryAllBalls = array_chunk($aryAllBalls,$intRegCount); // The above breaks up into an array with 5 numbers each
// [0] contains the first 5 balls of all balls randomized, these are what are "picked"
$aryPickedBalls = $aryAllBalls[0];
sort($aryPickedBalls); // Sort them for display
$intPowerBall2 = rand(1,$intMaxPB);
$aryAllBalls2 = range(1,$intMaxReg); // array of numbers 1 - 59
shuffle($aryAllBalls2); // Randomize their order
$aryAllBalls2 = array_chunk($aryAllBalls2,$intRegCount); // The above breaks up into an array with 5 numbers each
// [0] contains the first 5 balls of all balls randomized, these are what are "picked"
$aryPickedBalls2 = $aryAllBalls2[0];
sort($aryPickedBalls2); // Sort them for display
echo "YOUR WINNING NUMBERS ARE: <br>",implode(' ',$aryPickedBalls),' PB: ',$intPowerBall,"<br>\n<br>\n";
echo "You picked: <br>",implode(' ',$aryPickedBalls2),' PB: ',$intPowerBall2,"<br>\n<br>\n";
foreach($aryPick as $key=>$val) {
if (in_array($val,$aryPickedBalls2)) {
echo '<strong>',$val,'</strong> ';
}
else {
echo $val,' ';
unset($aryPick[$key]); // Remove it since it didn't match
}
}
$bMatchPB = ($intPower == $intPowerBall2); // Set here since checked in 3 places...
if ($bMatchPB) {
echo 'PB: <strong>',$intPower,"</strong><br>\n<br>\n";
}
else {
// At this point, $aryPick will only contain matching numbers...
$intMatches = count($aryPick);
echo 'You matched '.$intMatches,' numbers and did ';
if (!$bMatchPB) { echo 'not '; }
echo "match the PowerBall number.<br><br>\n\n";
}
if ($intMatches>=3 || $bMatchPB) {
$intWinnings = 0;
switch ($intMatches) {
case 0:
if ($bMatchPB) { $intWinnings = 3; }
break;
case 1:
if ($bMatchPB) { $intWinnings = 4; }
break;
case 2:
if ($bMatchPB) { $intWinnings = 7; }
break;
case 3:
if ($bMatchPB) {
$intWinnings = 100;
} else {
$intWinnings = 7;
}
break;
case 4:
if ($bMatchPB) {
$intWinnings = 10000;
} else {
$intWinnings = 100;
}
break;
case 5:
if ($bMatchPB) {
$intWinnings = $intGrandPize;
} else {
$intWinnings = 200000;
}
break;
default:
echo "ERROR: Winning Combination not defined in systen!!!<br>\n";
}
echo "<strong>YOU ARE A WINNER!!!!</strong><br>\n";
echo 'You Won: $'.number_format($intWinnings,0),"<br>\n";
}
}
//$quick_pick = array_slice($numberRange, 0, 6);}
//$numberRange = range(1, $intMaxReg);
//shuffle($numberRange);
elseif (count($_POST)>0) {
$aryPick = array();
$intPower = 0;
for($t=1;$t<=$intRegCount;$t++) {
if (isset($_POST['num'.$t])) {
$intPick = (int)$_POST['num'.$t];
if ($intPick > 0 && $intPick <= $intMaxReg && !in_array($intPick,$aryPick)) {
$aryPick[] = $intPick;
}
}
}
if (isset($_POST['Power']) && (int)$_POST['Power'] > 0 && $_POST['Power'] <= $intMaxPB) {
$intPower = (int)$_POST['Power'];
}
if (count($aryPick) < 5 || $intPower == 0) {
echo "<font color='red'>'*Five unique numbers and a PowerBall selection are Required*'</font>";;
}
else {
// Have valid numbers...
sort($aryPick); // For if you are going to display them, they will be in order...
// Pick your winners
$aryAllBalls = range(1,$intMaxReg); // array of numbers 1 - 59
shuffle($aryAllBalls); // Randomize their order
$aryAllBalls = array_chunk($aryAllBalls,$intRegCount);
// The above breaks up into an array with 5 numbers each
// [0] contains the first 5 balls of all balls randomized, these are what are "picked"
$aryPickedBalls = $aryAllBalls[0];
sort($aryPickedBalls); // Sort them for display
echo "YOUR WINNING NUMBERS ARE: <br>",implode(' ',$aryPickedBalls),' PB: ',$intPowerBall,"<br>\n<br>\n";
echo "You Picked: ";
foreach($aryPick as $key=>$val) {
if (in_array($val,$aryPickedBalls)) {
echo '<strong>',$val,'</strong> ';
}
else {
echo $val,' ';
unset($aryPick[$key]); // Remove it since it didn't match
}
}
$bMatchPB = ($intPower == $intPowerBall); // Set here since checked in 3 places...
if ($bMatchPB) {
echo 'PB: <strong>',$intPower,"</strong><br>\n<br>\n";
}
else {
echo 'PB: '.$intPower,"<br>\n<br>\n";
}
// At this point, $aryPick will only contain matching numbers...
$intMatches = count($aryPick);
echo 'You matched '.$intMatches,' numbers and did ';
if (!$bMatchPB) { echo 'not '; }
echo "match the PowerBall number.<br><br>\n\n";}}
// HERE YOU WOULD DO SOMETHING TO SAY HOW MUCH THEY WON
$intMatches = count($aryPick);
$bMatchPB = ($intPower == $intPowerBall);
if ($intMatches>=3 || $bMatchPB) {
$intWinnings = 0;
switch ($intMatches) {
case 0:
if ($bMatchPB) { $intWinnings = 3; }
break;
case 1:
if ($bMatchPB) { $intWinnings = 4; }
break;
case 2:
if ($bMatchPB) { $intWinnings = 7; }
break;
case 3:
if ($bMatchPB) {
$intWinnings = 100;
} else {
$intWinnings = 7;
}
break;
case 4:
if ($bMatchPB) {
$intWinnings = 10000;
} else {
$intWinnings = 100;
}
break;
case 5:
if ($bMatchPB) {
$intWinnings = $intGrandPize;
} else {
$intWinnings = 200000;
}
break;
default:
echo "ERROR: Winning Combination not defined in systen!!!<br>\n";
}
echo "<strong>YOU ARE A WINNER!!!!</strong><br>\n";
echo 'You Won: $'.number_format($intWinnings,0),"<br>\n";
}
?>