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

青灯夜游
Release: 2023-03-15 14:10:02
Original
3676 people have browsed it

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)
Copy after login
  • $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);
?>
Copy after login

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template