Chris
Chris

Reputation: 67

PHP, Echoing an array into a string of comma seperated values

I have a multi select box i am using to allow users to select multpile users, this is fine but the $_POST output is an array.

How would i get these values to be formatted like so

100,200,300,400

So i need to echo out the values, add a comma, but dont add the comma for the last value

Any help would be grand.

Cheers

Upvotes: 0

Views: 659

Answers (2)

user142162
user142162

Reputation:

$array = array(100, 200, 300, 400); // Or get from your $_POST value or what have you

echo implode(',', $array); // "100,200,300,400"

Upvotes: 1

sdleihssirhc
sdleihssirhc

Reputation: 42496

You could use implode:

return implode(',', $_POST['users']);

Upvotes: 8

Related Questions