In PHP, you can use the implode() function to convert an array into a string. It can convert a one-dimensional array into a string; the syntax format is "implode(array)", which will return a A string composed of array elements.
Recommended: "PHP Video Tutorial"
implode() function can convert a one-dimensional array into characters String, returns a string composed of array elements.
The syntax format is as follows:
implode($glue, $array) //或者 implode($array)
Parameters:
$glue is used to set a string, specified The content placed between the array elements, that is, using $glue to connect each element of the array together. By default, $glue is an empty string ("");
$array is Array to be converted.
Tip: The $glue parameter of the implode() function is optional and can be omitted. However, for backward compatibility, it is recommended that you use two parameters.
Return value: A string composed of array elements.
Example:Use the implode() function to convert the array into a string.
<?php header('content-type:text/html;charset=utf-8'); $arr = ['php中文网','PHP教程','http://php.cn','implode()函数','数组转字符串']; $str = implode($arr); echo $str.'<br>'; $str = implode(' ',$arr); echo $str.'<br>'; $str = implode(',',$arr); echo $str.'<br>'; $str = implode('--',$arr); echo $str.'<br>'; ?>
Output:
php中文网PHP教程http://php.cnimplode()函数数组转字符串 php中文网 PHP教程 http://php.cn implode()函数 数组转字符串 php中文网,PHP教程,http://php.cn,implode()函数,数组转字符串 php中文网--PHP教程--http://php.cn--implode()函数--数组转字符串
For more programming-related knowledge, please visit: Introduction to Programming! !
The above is the detailed content of How to convert array to string in php?. For more information, please follow other related articles on the PHP Chinese website!