Home > Article > Backend Development > How to convert array into string in php
php method to convert an array into a string: first create a PHP sample file; then define an array data as "$arr"; then use the "implode($arr);" method to convert the array into String; finally output the conversion result.
Recommended: "PHP Video Tutorial"
The operating environment of this tutorial: Windows 7 system, PHP version 5.6, This method works for all brands of computers.
PHP implode(): Array to string
implode() function can convert a one-dimensional array into a string. The syntax format is as follows:
implode($glue, $array) or implode($array)
Among them, $glue is used to set a string, indicating that $glue is used to connect 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 $arr = ['PHP中文网','PHP教程','//m.sbmmt.com/php/','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教程//m.sbmmt.com/php/implode()函数数组转字符串 PHP中文网 PHP教程 //m.sbmmt.com/php/ implode()函数 数组转字符串 PHP中文网,PHP教程,//m.sbmmt.com/php/,implode()函数,数组转字符串 PHP中文网--PHP教程--//m.sbmmt.com/php/--implode()函数--数组转字符串
The above is the detailed content of How to convert array into string in php. For more information, please follow other related articles on the PHP Chinese website!