How to store an array as a comma seperate list in a variable?

Experts,

I have an array of information that is passed by my form.  I have been able to process the form data passed using a foreach loop such as:

foreach($_POST[departments] as $departments) {
echo $department;
echo '<br />';
}

The code above prints something like this:

department1
department2
department3
etc.

How can I store the values passed by my form in a variable?  The variable should store the information in the following format:

department1, department2, department3, etc.
evibesmusicAsked:
Who is Participating?
 
hieloCommented:
if you need comma + Space then the first argument to implode() shoud be a COMMA + space instead of just comma:
$myList = implode(", ", $_POST['departments']);
echo $myList;
0
 
hieloCommented:
$myList = implode(",", $_POST['departments']);
echo $myList;
0
 
evibesmusicAuthor Commented:
@hielo:

You are awesome as always.  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.