Poker dice combinations
It can be hard to see how all this works together. (Remember, the value $i will be translated to a number before the HTML page is printed.) The value of the current die is stored as the value of the keepIt checkbox. Note how the name of the checkbox will correspond to the die name. If it's the first roll, the function also prints out the keepIt checkbox corresponding to this die. If the checkbox has been checked, the value associated with that checkbox will be passed to the program. Any checkbox the user does not check will not be passed to the program. Checkboxes in PHP are a little different than some of the other form elements, because they only send a value if they are checked. When PHP sees these variables with the same name but different indices, it will automatically create an array.
The checkboxes are all called keepIt, and all have an index. The general strategy for them is this: If it's the first turn, I'll print out a checkbox under each die. The checkboxes that appear sometimes are special. print out submit button and end of table print out a checkbox on first roll only Regardless, I inform the user which roll it is, and change the value of $secondRoll so it reflects what should happen the next time this program is called (which will happen when the user clicks on the Submit button). If $secondRoll is TRUE, the program will call the evaluate() function, which will tally any losses or winnings. I chose to give it the value TRUE when the user is on the second roll and FALSE when on the first roll. The $secondRoll variable is used to keep track of whether the user is on the second roll. On the second roll, there are no checkboxes (because the user will need to start with all fresh dice on the next turn) and the program keeps track of the player's score by adding money for various combinations. On the first roll, the user is given the ability to save a roll with a checkbox, and no scoring is performed. Each turn consists of two possible rolls. If you look carefully at the program as it is running, you'll see it runs in two different modes. This function rolls the dice and prints them to the screen. The program then calls the rollDice() function, which will be described momentarily. If the $cash variable has not yet been created, the user will get a starting value of $100. The first if statement checks this condition. If the user has never been to the page before, the value for the $cash variable will be null. The program will have different behavior based on which form elements (if any) have values. The user will feel like he or she is playing the same game for several turns, but actually each time he or she rolls the dice, the entire program runs again. It's important to understand how timing works in this program. The first order of business is to see if this is the first time the user has come to this page. check to see if this is first time here