php 如何将数组转换为逗号分隔的单词字符串?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9895450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:52:20 来源:igfitidea点击:
How to transform array to comma separated words string?
提问by m3tsys
Possible Duplicate:
How to create comma separated list from array in PHP?
可能的重复:
如何在 PHP 中从数组创建逗号分隔列表?
My array looks like this:
我的数组如下所示:
Array
(
[0] => lorem
[1] => ipsum
[2] => dolor
[3] => sit
[4] => amet
)
How to transform this to a string like this with php?
如何使用php将其转换为这样的字符串?
$string = 'lorem, ipsum, dolor, sit, amet';
回答by omabena
$arr = array ( 0 => "lorem", 1 => "ipsum", 2 => "dolor");
$str = implode (", ", $arr);
回答by Adam
Make your array a variable and use implode.
使您的数组成为变量并使用内爆。
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo $comma_separated; // lastname,email,phone