Implementation method: 1. Use the array_merge() function to merge multiple arrays into one array, the syntax is "array_merge(array 1, array 2, array 3...)"; 2. Use the implode() function Convert the merged array to a string using the syntax "implode("connection character", merged array)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Required to convert arrays into strings Divided into two parts:
Merge arrays: merge multiple arrays into one array
Array to string: merge Convert the resulting array to a string
Implementation steps:
1. Use the array_merge() function to merge arrays
array_merge(array1,array2,array3...)
You can merge two or more arrays. When the keys of the two arrays are the same, the value of the latter array overwrites the value of the previous array.
<?php $a = [1,'2'=>2,'a'=>'a','b'=>'b']; $b = [1,'2'=>3,'a'=>'c','b'=>'d','c'=>'e']; $c = array_merge($a,$b); var_dump($a); var_dump($b); var_dump($c); ?>
2. Use the implode() function to convert the merged array to a string
implode($glue ,$arr)
The function can convert a one-dimensional array into a string, and will return a string composed of array elements and the "$glue" character.
var_dump($c); var_dump(implode($c)); var_dump(implode("",$c)); var_dump(implode(",",$c)); var_dump(implode("-",$c)); var_dump(implode("::",$c));
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to merge arrays into strings in php. For more information, please follow other related articles on the PHP Chinese website!