Home  >  Article  >  Backend Development  >  How to convert array into string in php?

How to convert array into string in php?

青灯夜游
青灯夜游Original
2020-07-17 14:57:512429browse

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.

How to convert array into string in php?

PHP implode() function

implode() function can return an array composed of elements String. [Related recommendations: PHP Tutorial]

How to convert array into string in php?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn