gush, this array issue doesn't really want to enter my head. Always having problem with it.
I have, after quite some effort, succeeded in storing data in an array, which looks like this:
Expand|Select|Wrap|Line Numbers
- array(10) {
- ["Economically Active Population"]=>
- array(41) {
- [0]=>
- array(2) {
- [0]=>
- string(4) "1980"
- [1]=>
- string(3) "179"
- }
- [1]=>
- array(2) {
- [0]=>
- string(4) "1981"
- [1]=>
- string(3) "179"
- }
- [2]=>
- array(2) {
- [0]=>
- string(4) "1982"
- [1]=>
- string(3) "179"
- }
- ......
- }
- ["Population - Aged 0 - 14"]=>
- array(62) {
- [0]=>
- array(2) {
- [0]=>
- string(4) "1980"
- [1]=>
- string(3) "179"
- }
- [1]=>
- array(2) {
- [0]=>
- string(4) "1981"
- [1]=>
- string(3) "179"
- }
- [2]=>
- array(2) {
- [0]=>
- string(4) "1982"
- [1]=>
- string(3) "179"
- }
- .......
Now, I need to read from that array. And there, I don't succeed in getting it correctly off the ground.
I want to display the variable name in a cell, and then (at least for the moment) only the values (not the years) in following ones, and then turn to the next row.
This is how the code looks like, but the result is somewhat strange, putting me multiple rows with the same rows, in which all items appear, one after the other:
Expand|Select|Wrap|Line Numbers
- for ($z = 0; $z < 10; $z++)
- {
- echo "<tr>";
- foreach ($arr as $key1 => $item)
- {
- echo "<td>" . $key1 . "</td>";
- foreach($item as $key => $value)
- {
- echo "<td>" . $value[1] . "</td>";
- }
- }
- echo "</tr>";
- }
Can anyone give me a hint what the proper way of writing is, to retrieve the elements correctly?
Thanks a lot.