1

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

0

1 Answer 1

3

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.