0

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

2 Answers 2

8

You could use implode:

return implode(',', $_POST['users']);
Sign up to request clarification or add additional context in comments.

2 Comments

You should use implode. Implode is quite efficient compared to alternatives (especially when doing it yourself).
I'm more used to JavaScript than PHP, so I first just tried echo $_POST['users']. I was once again reminded that PHP and JavaScript are, in fact, different languages.
1
$array = array(100, 200, 300, 400); // Or get from your $_POST value or what have you

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

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.