I have this set of code here out of my text book that i'm working with. I understand how all the code works except for one part that i'm not to sure what it's doing. The part that confuses me is in the if statement for example the $FaceNamesPlural[$Die1-1] the part that stumps me is the [$Die1-1] not really understanding what the -1 part is doing my only guess is that it's maybe pulling the element thats index is 1 in the array? Thanks for any feedback.
<?php
$FaceNamesSingular = array("one", "two", "three", "four", "five", "six");
$FaceNamesPlural = array("ones", "twos", "threes", "fours", "fives", "sixes");
function CheckForDoubles($Die1, $Die2)
{
global $FaceNamesSingular;
global $FaceNamesPlural;
if ($Die1 == $Die2) //Doubles
echo "The roll was double ", $FaceNamesPlural[$Die1-1], ".<br>";
if ($Die1 != $Die2) //not Doubles
echo "The toll was a ", $FaceNamesSingular[$Die1-1], " and a ", $FaceNamesSingular[$Die2-1], ".<br>";
}
function DisplayScoreText($Score)
{
if ($Score == 2)
echo "You rolled snake eyes!<br>";
if ($Score == 3)
echo "You rolled a loose deuce!<br>";
if ($Score == 5)
echo "You rolled a fever five!<br>";
if ($Score == 7)
echo "You rolled a natural!<br>";
if ($Score == 9)
echo "You rolled a nina!<br>";
if ($Score == 11)
echo "You rolled a yo!<br>";
if ($Score == 12)
echo "You rolled boxcars!<br>";
}
$Dice = array();
$Dice[0] = rand(1,6);
$Dice[1] = rand(1,6);
$Score = $Dice[0] + $Dice[1];
echo "<p>";
echo "The total score for the roll was $Score. <br>";
checkForDoubles($Dice[0], $Dice[1]);
DisplayScoreText($Score);
echo "</p>";
?>