Home > Article > Backend Development > What function can convert array to string in php
The implode() function in php can convert an array into a string. implode() is used to convert a one-dimensional array into a string and return it. It accepts two parameters. The first parameter can set the connector, which can connect each element of the array together. It can be omitted and defaults to an empty character; syntax "implode("connector",array)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The implode() function in php can convert an array into Convert to string.
implode() function can convert a one-dimensional array into a string and return a string composed of array elements. The syntax format is as follows:
implode(separator,array)
Parameter | Description |
---|---|
separator | Optional. Used to set a string, specify the content to be placed between array elements, and connect each element of the array together. Default is "" (empty string). |
array | Required. Arrays to be combined into strings. |
Example 1: Set the first parameter of the implode() function
<?php $arr = array(1,2,3,4,5,6,7,8,9); $str = implode(",",$arr); echo $str; var_dump($str); $str = implode("-",$arr); echo $str; var_dump($str); $str = implode("::",$arr); echo $str; var_dump($str); ?>
Example 2: Omit the first parameter
<?php $arr = array(1,2,3,4,5,6,7,8,9); $str = implode("",$arr); echo $str; var_dump($str); $str = implode($arr); echo $str; var_dump($str); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What function can convert array to string in php. For more information, please follow other related articles on the PHP Chinese website!