How to convert array to string in php? The following article will introduce it to you. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
In PHP, you can use the explode() function to convert a string into a one-dimensional array, or you can use a function with the opposite function - implode( ) to convert the array into a string.
implode() function can convert a one-dimensional array into a string. Its syntax format is as follows:
implode($glue, $array) 或者 implode($array)
Among them, $glue is used to set a string, indicating the use of $ Glue connects each element of the array together. By default, $glue is an empty string; $array is the array that needs to be converted.
Tip: The $glue parameter of the implode() function is optional and can be omitted.
[Example] Use the implode() function to convert an array into a string.
<?php header("Content-Type: text/html; charset=utf-8"); $arr = ['php中文网','PHP教程','https://www.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>'; ?>
The running results are as follows:
php中文网PHP教程https://www.php.cnimplode()函数数组转字符串 php中文网 PHP教程 https://www.php.cn implode()函数 数组转字符串 php中文网,PHP教程,https://www.php.cn,implode()函数,数组转字符串 php中文网--PHP教程--https://www.php.cn--implode()函数--数组转字符串
For more related knowledge, please pay attention to PHP Chinese website! !
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!