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

How to convert string in array to array in PHP

Guanhui
Release: 2023-03-01 08:18:02
Original
3006 people have browsed it

How to convert string in array to array in PHP

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);
Copy after login

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"    
}
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template