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

How to convert php array string to string

藏色散人
Release: 2023-03-07 16:50:02
Original
5272 people have browsed it

How to convert PHP array string to string: 1. Use PHP implode function to convert the array into string, with syntax such as "implode(glue, pieces)"; 2. Use a loop to traverse the array elements and splice them into String.

How to convert php array string to string

The operating environment of this tutorial: windows10 system, php5.6. This article is applicable to all brands of computers.

Recommended: "PHP Video Tutorial"

Two methods of converting PHP arrays to strings

Method one, use The built-in implode function

Method 2 uses a loop to traverse the array elements and 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

The above is the detailed content of How to convert php array string 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