Home>Article>Backend Development> What are the php array to string functions?

What are the php array to string functions?

青灯夜游
青灯夜游 Original
2022-05-10 17:57:46 3466browse

There are 2 conversion functions: 1. implode(), the syntax is "implode($glue,$arr)", which will return a string composed of array elements and "$glue" characters. 2. join(), the syntax is "join($glue,$arr)", which can convert a one-dimensional array into a string.

What are the php array to string functions?

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

PHP provides two arrays Functions to convert to string: implode() and join().

1. implode() function

implode() function can convert a one-dimensional array into a string. The syntax is as follows:

implode($glue,$arr)
##Parameter Description Optional. Used to set a string, indicating that $glue is used to connect each element of the array together. By default, $glue is an empty string. Required. Arrays to be combined into strings.
$glue
$arr
#implode() function returns a string composed of array elements and the "$glue" character.

Example:


What are the php array to string functions?

2. join() function

join() function returns A string composed of array elements.

The join() function is actually an alias of the implode() function. Its usage and function are the same as the implode() function. You can refer to the above directly.

What are the php array to string functions?

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of What are the php array to string functions?. 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