Welcome Guest, Not a member yet? Register   Sign In
Accessing Array Elements
#1

[eluser]fildawg[/eluser]
Hi, I'm loading an array from a CSV file. The file looks like this:
Code:
name, email_address
name1, email1
name2, email2
name3, email3

I'm now attempting to loop through the array for further processing. How can I access each array element? I've gotten this far (using print_r to validate the array has content):
Code:
foreach ($data as $field)
        {
            print_r($field);
        }

How can I access each field?

TIA!!
#2

[eluser]mikelbring[/eluser]
try this:

Code:
foreach ($arr as $key => $value) {
    echo "Key: $key; Value: $value<br />\n";
}
#3

[eluser]Sbioko[/eluser]
Code:
foreach($data as $field=>$value)
{
    echo $value; // Value of item
}
#4

[eluser]mikelbring[/eluser]
Same thing I said heh. Either one should work.
#5

[eluser]Sbioko[/eluser]
When I posted this, I didn't see your reply. Sorry :-)




Theme © iAndrew 2016 - Forum software by © MyBB