I have a program that simulates the Powerball Lottery game, i have been working on it for weeks now. My issue is with the quick pick option. when the quick pick numbers match the winning numbers it doesn't show the matches. If the user enters the numbers manually it does. Can anyone look at my code and tell me what adjustments to make to correct this. I'm not getting any errors it just doesnt show the matches and amount that was won.
<?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,$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 {
// 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";
}
}
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";
}
?>