How to convert a string in an array into an array in PHP
First use the function "implode()" to splice the array into a string, splice The separator is the separator of the strings in the array; then, after concatenating the strings, use the function "explode()" to split them into arrays.
Sample code:
$arr = ['1.a.d.f.g.r.t', '1.2.3.4.5.6.7.8.9', '0.a.1.r.g.k.5']; $arr = implode('.', $arr); $arr = explode('.', $arr); var_dump($arr);
Print result:
array(23) { [0]=> string(1) "1" [1]=> string(1) "a" [2]=> string(1) "d" [3]=> string(1) "f" [4]=> string(1) "g" [5]=> string(1) "r" [6]=> string(1) "t" [7]=> string(1) "1" [8]=> string(1) "2" [9]=> string(1) "3" [10]=> string(1) "4" [11]=> string(1) "5" [12]=> string(1) "6" [13]=> string(1) "7" [14]=> string(1) "8" [15]=> string(1) "9" [16]=> string(1) "0" [17]=> string(1) "a" [18]=> string(1) "1" [19]=> string(1) "r" [20]=> string(1) "g" [21]=> string(1) "k" [22]=> string(1) "5" }
Recommended tutorial: "PHP Tutorial 》
The above is the detailed content of How to convert string in array to array in PHP. For more information, please follow other related articles on the PHP Chinese website!