Home > Article > Backend Development > 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 = ['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);
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!