Link to home
Start Free TrialLog in
Avatar of evibesmusic
evibesmusicFlag for United States of America

asked on

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.
Avatar of hielo
hielo
Flag of Wallis and Futuna image

$myList = implode(",", $_POST['departments']);
echo $myList;
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of evibesmusic

ASKER

@hielo:

You are awesome as always.  Thanks.