Home >Backend Development >PHP Problem >How to convert php array to string
In PHP, you can use the implode function to convert array into string. The syntax is "function implode ($glue = "", array $pieces) {}". The return value is a combination of array elements. String.
Recommended: "PHP Video Tutorial"
Array to String
implode
Method introduction:
function implode ($glue = "", array $pieces) {}
There are two main parameters
One is the connector (glue: the meaning of glue), the default Is an empty string
One is an array
Use
$test = array("hello","world","php"); echo implode("-",$test);
Result:
hello-world-php
What if it is an array in the form of K-V?
$test = array("h"=>"hello","w"=>"world","p"=>"php"); echo implode("-",$test);
The result is still hello-world-php
It means it still only works on value.
The above is the detailed content of How to convert php array to string. For more information, please follow other related articles on the PHP Chinese website!