Arrays

I am trying to get my head around arrays and have spent all morning reading and trying without success

I have a flat file that has records. For each top level record there will be sub level records that relate to the head record BUT they can be in any order.

So the data could be like:
0 ID
1 Name
1B
2Date
2Place
1D
2Date
2Place
1More data comprising many rows that I am not interested in
0 ID
1 Name etc etc

The 1 level records can be in any order but the 2 level records only relate to the 1 above.

What I need to do is step through the file and pull out the 1 and 2 records and output them to another file in a specific order.

I thought that a 2 dimensional array (array of arrays) would do this whereby I can step through the input file using a variable for loop and then write to the appropriate element in an array and then write that array back to a new file.

I seem to be having issues with writing the data to the array in the for loop.

I have tried
[php]$g_data[’$rec_no’][1] = $n;[/php]

and

[php]$g_data[$rec_no][1] = $n;[/php]

But nothing seems to being written to the array.

Anyone got any hints to help me along?

Have you tried dumping the array to see what it holds?

I marked this as solved as I ended up doing it another way with a single array. Not ideal but it works and that is what matters.

Sponsor our Newsletter | Privacy Policy | Terms of Service