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.
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 = ['Lucy','Mike','Jery','Haly']; $str = implode(',', $arr); // var_dump($str); //方法二,利用循环遍历数组元素拼接成字符串 $arr1 = ['Lucy','Mike','Jery','Haly']; $str1 = ''; foreach ($arr1 as $key => $value) { $str1 .=','.$value; } var_dump($str1);
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!