How php converts an one-dimensional array to a string
This article mainly introduces how php converts one-dimensional arrays into strings, which is very detailed and has a certain reference value. Friends who are interested must read it!
Php converts an one-dimensional array into a string: 1, iterate through the array using the foreach statement, concatenating array elements into strings using ". =" in the loop body; 2, using the implode () function, syntax "implode ('delimiter', $array)".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Method 1: loop through the array using the foreach statement to concatenate the array elements into strings
Output:
Method 2: using the implode () function
The implode () function converts an one-dimensional array to a string in the following syntax format:
Implode ($glue, $array) or implode ($array)
Where $glue is used to set a string to indicate that each element of the array is concatenated using $glue. By default, $glue is an empty string, and $array is the array to be converted.
Tip: the $glue parameter of the implode () function is optional and can be omitted.
Example
Output:
These are all the contents of the article "how php converts one-dimensional arrays into strings". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!