开发者

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

开发者 https://www.devze.com 2023-02-07 15:43 出处:网络
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.

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,4开发者_如何学C00

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


You could use implode:

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


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

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

精彩评论

暂无评论...
验证码 换一张
取 消