Hi all
I'm writing a set of functions that will return entire datasets to populate a table.
I'm trying to work out how to generate an array that will populate a table shaped like this:
+----------------+----+----+----+
| | 27 | 19 | 10 |
| Row 1 | 35 | 29 | 08 |
| | 39 | 27 | 49 |
| | 40 | 41 | 14 |
+----------------+----+----+----+
| | 29 | 35 | 19 |
| Row 2 | 47 | 32 | 37 |
| | 19 | 21 | 14 |
| | 17 | 19 | 15 |
+----------------+----+----+----+
| | 39 | 18 | 27 |
| Row 3 | 23 | 19 | 18 |
| | 38 | 17 | 45 |
| | 27 | 32 | 49 |
+----------------+----+----+----+
Once this array has been generated, I'll use something like:
for ($row = 0; $row<count($arrayname); $row++)
{
extract ($arrayname[$row]); // this is the row
// loop to extract the 4 'sub rows' and their columns here
}
I've done some reading and found this tutorial helpful:
http://www.webcheatsheet.com/PHP/multidimensional_arrays.php
However, I'm not quite sure of the terminology and how it applies to what I'm trying to do.
I would describe the layout as 3 rows with 4 subrows each, and X columns.
When I parse the array, I don't know how many rows there will be, and I don't know how many columns there will be either, because they depend on what values are given to the function in the first place. There will always be 4 subrows though.
It seems to make sense to make the main rows and subrows associative arrays because it's easy to extract the values and assign them to variables; the columns array can be numeric.
I think this is the correct design for 3 main rows and 2 columns (4 subrows, as always).
Array
(
[mainrow1] => Array
(
[subrow1] => Array
(
[10]
[15]
)
[subrow2] => Array
(
[17]
[23]
)
[subrow3] => Array
(
[10]
[15]
)
[subrow4] => Array
(
[17]
[23]
)
)
[mainrow2] => Array
(
[subrow1] => Array
(
[10]
[15]
)
[subrow2] => Array
(
[17]
[23]
)
[subrow3] => Array
(
[10]
[15]
)
[subrow4] => Array
(
[17]
[23]
)
)
)
Can anyone assist with a script which would generate, and read, the shape of array I'm trying to build? Or offer any pointers? If my example layouts and terminology are incorrect I'd also welcome any comments!
Thanks!