Home >Backend Development >PHP Problem >How to convert array into string in php?
In PHP, you can use the implode() function to convert an array into a string. The implode() function can return a string composed of array elements.
PHP implode() function
implode() function can return an array composed of elements String. [Related recommendations: PHP Tutorial]
Note: The implode() function accepts two parameter orders. However, due to historical reasons, explode() does not work. You must ensure that the separator parameter comes before the string parameter.
Syntax
implode(separator,array)
Parameters:
separator Optional. Specifies what is placed between array elements. Default is "" (empty string).
array Required. Arrays to be combined into strings.
Note: The separator parameter of the implode() function is optional. However, for backward compatibility, it is recommended that you use two parameters.
Example;
$arr2= array('Hello','World!','hh','oo'); $str = implode(" ",$arr2); print_r($str);
Output:
Hello World! hh oo
Related learning recommendations:PHP programming from entry to proficiency
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!