Hello everyone. I am doing my first PHP mini project, which is a D&D style dice rolling offspring generator for a game I play online. I am creating a 6-sided dice roll using mt_rand(1, 6). Depending on the outcome of each roll, a different number of rolls is required next time.
[php]
$total=mt_rand(1, 6); //Total number of offspring
$puppies=$total; //This variable gets eaten by the loop below (if you have any ideas please say so!)
[/php]
So now we have a random number 1-6 and I want to roll dice equal to that number, and record the values. I have attempted several and none seem to work.
[php]
for ($puppies; $puppies>=1; $puppies–)
{
${death.$i} = mt_rand(1, 6);
}
// OR
$death = mt_rand(1, 6);
$fatality[] = $death[0];
// OR
$fatality = array (“death1”=>mt_rand(1, 6), “death2”=>mt_rand(1, 6));
[/php]
So ideally I want it to say, you have x total, roll x times and record those numbers either as variables or as an array. There’d only ever be six maximum so I guess it doesn’t matter which way. I’ve tried making six ${$fatality[0]} = mt_rand(1, 6); but I obviously don’t want to display 6 dice rolls if I only had 3 to start with (and thus need 3 dice rolls). Equally, I guess this method would work if I knew how to echo only the number of $fatality as $total?
Any help is greatly appreciated! Many thanks!