Home >Backend Development >PHP Problem >How to convert array to string in php

How to convert array to string in php

藏色散人
藏色散人Original
2021-03-11 09:50:006259browse

php method to convert an array into a string: first create a PHP sample file; then define an array; finally use the "implode(",",$array);" method to convert the array into a string. Can.

How to convert array to string in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php array to string

The code is as follows:

$array=["php","Java","web"];
$result=implode(",",$array);

implode() function

implode returns a string composed of array elements.

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.

Note: The separator parameter of the implode() function is optional. However, for backward compatibility, it is recommended that you use two parameters.

Note: This function is binary safe.

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.

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to convert array to 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
Previous article:How to hide tags in phpNext article:How to hide tags in php