[thelist] Php array, best way to...

Diane Soini dianesoini at earthlink.net
Tue Jul 13 16:47:46 CDT 2004


On Tuesday, July 13, 2004, at 01:48 AM, thelist-request at lists.evolt.org 
wrote:
>
>> How are you building the array to begin with...
>
> It's coming from a CSV file.
>
>
>> More information about how the array is built and what it
>> should do would help in suggesting the bet way to retrieve sub arrays.
>
> I'm parsing a CSV file and placing each "record" and its "fields" into
> the array. An array of arrays, actually.
>

This will probably be a silly answer because I'm not a programmer and 
certainly not a PHP expert, but here goes...

I'm thinking about how the original array of records could be 
constructed to allow you to get out what you are looking for down the 
line.

As a visual thinker I imagine an HTML table. You want to get a column 
out. If I were to do it as HTML (not really as HTML, but in my head as 
HTML) I might imagine putting each value into  a <td> and put the 
column value (<th>A</th><th>B</th>) as the class name on the <td>. <td 
class="A">val</td><td class="B">val</td>. Then if I wanted column A, I 
would use the DOM to find all <td> with className of A and get the 
innerText.

Imagining (kind of translating it in my visual mind) it in javascript, 
I would probably make my array of arrays an array of Objects (yeah, an 
array is an Object...I know).
array[0] = {columnValue:"A",itemValue:somearray}
array[1] = {columnValue:"B",itemValue:someotherarray}
...etc...

Something like that. Then I could loop through and gather those 
elements with a columnValue property of A and then I'd have a handle to 
those itemValue arrays. There are probably many other better ways to 
achieve this, but they'd be kind of similar.

Don't know if this is anywhere near to being of any use, and it 
probably isn't if I was able to think it up. Plus I don't know if PHP 
will behave similarly. I imagine that it might.

Diane

> Walter
***
Don't be afraid to try something new. An amateur built the ark. 
Professionals built the Titanic. -unknown



More information about the thelist mailing list