开发者

How to create a variable from a array with all values into ihe variable separated by 'comma'?

开发者 https://www.devze.com 2023-01-28 09:01 出处:网络
I Have to iterate through an array, such that I can get all values of the array inside my desired variable in csv format?

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
}
0

上一篇:

:下一篇

精彩评论

暂无评论...
验证码 换一张
取 消