In PHP, you can use implode() to convert an array into a string, and use the comma delimiter "," to connect each element of the array together; the conversion syntax is "implode(',', $arr)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php converts the array For strings connected with comma delimiters
In PHP, you can use implode() to convert an array into a string.
implode() function can convert a one-dimensional array into a string. Its syntax format is as follows:
implode([$glue,] $array)
$glue
is used to set A separator (connector), which means using $glue
to connect each element of the array together,
$array
needs to be converted array.
Example: Convert array to string concatenated with comma delimiters
<?php header("Content-type:text/html;charset=utf-8"); $arr = array('Hello','World!','Beautiful','Day!'); echo implode(",",$arr); ?>
$glue parameter of the function is optional and can be omitted. By default
$glue is an empty string;
<?php header("Content-type:text/html;charset=utf-8"); $arr = array('Hello','World!','Beautiful','Day!'); echo implode($arr)."<br>"; echo implode(" ",$arr)."<br>"; echo implode("-",$arr); ?>
PHP Video Tutorial", "PHP ARRAY"
The above is the detailed content of How to convert array to comma delimited string in php. For more information, please follow other related articles on the PHP Chinese website!