Home >Backend Development >PHP Problem >What are the php array to string functions?
There are 2 conversion functions: 1. implode(), the syntax is "implode($glue,$arr)", which will return a string composed of array elements and "$glue" characters. 2. join(), the syntax is "join($glue,$arr)", which can convert a one-dimensional array into a string.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
PHP provides two arrays Functions to convert to string: implode() and join().
1. implode() function
implode() function can convert a one-dimensional array into a string. The syntax is as follows:
implode($glue,$arr)
Description | |
---|---|
$glue | Optional. 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.|
$arr | Required. Arrays to be combined into strings.
<?php $arr = array(1,2,3,4,5,6,7,8,9); var_dump(implode($arr)); var_dump(implode("",$arr)); var_dump(implode(",",$arr)); var_dump(implode("-",$arr)); var_dump(implode("::",$arr)); ?>
2. join() function
join() function returns A string composed of array elements. The join() function is actually an alias of the implode() function. Its usage and function are the same as the implode() function. You can refer to the above directly.<?php $arr = array(1,2,3,4,5,6,7,8,9); var_dump(join($arr)); var_dump(join(",",$arr)); var_dump(join("-",$arr)); ?>Recommended learning: "
PHP Video Tutorial"
The above is the detailed content of What are the php array to string functions?. For more information, please follow other related articles on the PHP Chinese website!