1

I have an array containing numbers 1-5 (sometimes more). All the members in the array can be displayed using the php function foreach. But, how can I display all the members of my array by storing it in a single variable as csv (like1, 2, 3, 4, 5), and thereby printing that variable only?

2
  • do you only want to know what's inside the array or do you actually have to work with that variable afterwards? Commented Mar 7, 2011 at 10:57
  • i want to work with it afterwards :) Commented Mar 7, 2011 at 11:10

1 Answer 1

5

You could use the function implode().

For example

$csv_var = implode(', ', $array);


Have a look at the Manual.

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.