I Have to iterate through an array, such that I can get all values of the array inside my desired variable in csv format?
My basic aim is to insert these csv values in to a column of db table.
开发者_开发百科Please guide to acheive this..
Thanks
use 'implode' in combination with a function dependant on your array structure.
i.e. implode(",", $array);
eg:
$array=array("value1", "value2", "value3");
echo implode(",",$array);
Would give you:
value1,value2, value3
Ideally your dataset will look like this:
$arrayofdata[rownumber][fieldnumber];
So rownumber 1 would have fieldnumber (or name) 1, 2, 3 etc..
You would then do:
// Loop through each row
foreach ($arrayofdata as $key){
echo implode(",", $arrayofdata[$key])."\r";
// joining each field with a comma, then moving onto a new line
}
精彩评论