View Single Post
Old 06-27-2012, 04:58 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Still not seeing a need to use multiple dimensions, but I don't know what you want in that output table.
You can use two arrays to simplify. The first is simply what the roll values are, and offsets will correspond to the roll value. You can then create a second array of the counts using array_count_values to pin the roll number to the count. Something like this:
PHP Code:
$aRolls = array();
$rolls 26;
$sides 6;

for (
$i 0$i $rolls; ++$i)
{
    
$aRolls[] = rand(1$sides);
}

$aValueCount array_count_values($aRolls);

print 
'<table><tr><th>Side</th><th>Roll Count</th></tr>';
for(
$i=1$i <= $sides; ++$i

    
printf('<tr><td>%d</td><td>%d</td></tr>'$i$aValueCount[$i]);
}
print 
'</table>'
So it still comes down to what you want inside that HTML. The $aRolls will contain each corresponding roll's 0 - 25 in this example, and the $aValueCounts associates the key as the value rolled with the value being the number of times it was rolled.
Fou-Lu is offline   Reply With Quote