![]() |
php print the array values to an html table
Hi I need to print the array values to an html table but I am not sure how to do it. Heres my code:
Code:
<!doctype html><html><head><title>Dice Roll Simulator</title></head> |
not sure exactly the layout you want but the general principle is to echo out the correct HTML e.g.
PHP Code:
|
What I want to do is assign each result in turn along with its roll number to a two dimensional array in the first for loop and print to an html table with a header row using a second program loop. Any help would be great.
|
That's what firepages has done there. If you want the side number and count separate, a simple division is all that's required in the print.
So like so: PHP Code:
Edit: Wait you want a two dimensional array? What exactly is to be in it? |
What I want to do is use two separate for loops to roll a dice 26 times and assign each result in turn along with its roll number to a two dimensional array in the first for loop then count the total value of dice rolls over 26 throws and print to an html table.
|
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:
|
What I need to do is:
Use two separate for loops to roll a dice 26 times and assign each result in turn along with its roll number to a two dimensional array in the first for loop then count the total value of dice rolls over 26 throws and print to an html table with a header row using a second program loop. The total value of the dice rolls plus the average value per throw should be printed out. |
Still not seeing a need for multidimensional here. Not to mention it will increase complication to the calculations since you cannot use things like count and array_sum's on the entire array as they are not recursive.
This doesn't describe very well what the structure of the array should look like. The description you have specifies a two dimensional array, but the data provided is only one dimensional since the roll corresponds to the offset of the array itself, and so can be retrieved from the key. So what is the structure of the rolled array supposed to look like? As with the total value of the dice rolls, if that includes every value you need to increment a variable within the population of it if you are using multiple dimensions. The only alternative is to use a loop to count it as well since you cannot use count or array_sum to get this information from multiple dimensions, and this can be grouped into the second loop only if its intended to be used after the loop. If its a sum of the total number of rolls, then that can be calculated during the second loop. Show us what the array is supposed to look like, and what the HTML table should look like. |
This is what I have but im not sure if its right.
PHP Code:
|
| All times are GMT +1. The time now is 12:31 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.