CodeIgniter Forums
Accessing Array Elements - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Accessing Array Elements (/showthread.php?tid=27529)



Accessing Array Elements - El Forum - 02-13-2010

[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!!


Accessing Array Elements - El Forum - 02-13-2010

[eluser]mikelbring[/eluser]
try this:

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



Accessing Array Elements - El Forum - 02-13-2010

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



Accessing Array Elements - El Forum - 02-13-2010

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


Accessing Array Elements - El Forum - 02-13-2010

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