How to convert php array to string

L
Release: 2023-03-01 09:16:02
Original
4220 people have browsed it

How to convert php array to string

php array to string

PHP array to string Two methods for strings

Method one, use the built-in implode function

Method two, use a loop to traverse the array elements to splice them into a string

<?php
// PHP数组转字符串的方法
// 方法一:implode(glue, pieces)
$arr = [&#39;Lucy&#39;,&#39;Mike&#39;,&#39;Jery&#39;,&#39;Haly&#39;];
$str = implode(&#39;,&#39;, $arr);
// var_dump($str);
//方法二,利用循环遍历数组元素拼接成字符串
$arr1 = [&#39;Lucy&#39;,&#39;Mike&#39;,&#39;Jery&#39;,&#39;Haly&#39;];
$str1 = &#39;&#39;;
foreach ($arr1 as $key => $value) 
{
$str1 .=&#39;,&#39;.$value; 
}
var_dump($str1);
Copy after login

Recommended tutorial: " PHP Tutorial》

The above is the detailed content of How to convert php array to string. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!