Home >Backend Development >PHP Problem >How to convert array to comma delimited string in php

How to convert array to comma delimited string in php

青灯夜游
青灯夜游Original
2022-02-28 18:31:463773browse

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)".

How to convert array to comma delimited string in php

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(&#39;Hello&#39;,&#39;World!&#39;,&#39;Beautiful&#39;,&#39;Day!&#39;);
echo implode(",",$arr);
?>

How to convert array to comma delimited string in php

##implode( ) The

$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(&#39;Hello&#39;,&#39;World!&#39;,&#39;Beautiful&#39;,&#39;Day!&#39;);
echo implode($arr)."<br>";
echo implode(" ",$arr)."<br>";
echo implode("-",$arr);
?>

How to convert array to comma delimited string in php

Recommended learning: "

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does php cli mean?Next article:What does php cli mean?