Home  >  Article  >  Backend Development  >  How to convert php array to string

How to convert php array to string

藏色散人
藏色散人Original
2020-08-01 10:07:495093browse

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.

How to convert php array to 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!

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