what does $line mean in this piece of code?
Posted: Mon Jul 03, 2006 8:14 am
Pimptastic | Please use
Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm a raw beginner trying to learn how to save my form data as a csv file. I've got as far as finding fputcsv() and this piece of code that illustrates its use.
But I can't figure out what the line "foreach($list as $line)" means.
Well, I can, it means for each line in the array $list write a csv line in the file using "," as a separator.
But how does it mean that? Is there any significance in "$line" or could I write "foreach($list as $foobah)" ?
(I should test it and find out for myself but I can't right now.. not on this machine... when I get home)
Using fputcsv()Code: Select all
<?php
$list = array
(
"Peter,Griffin,Oslo,Norway",
"Glenn,Quagmire,Oslo,Norway",
);
$file = fopen("contacts.csv","w");
foreach ($list as $line)
{
fputcsv($file,split(',',$line));
}
fclose($file);
?>Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]