Home  >  Article  >  Backend Development  >  How to convert string to array in php

How to convert string to array in php

Guanhui
GuanhuiOriginal
2020-04-29 16:37:275655browse

How to convert string to array in php

php method to convert a string into an array

str_split() function definition and usage

str_split() function splits a string into an array.

Syntax

str_split(string,length)

Parameters

string Required. Specifies the string to be split.

length Optional. Specifies the length of each array element. The default is 1.

Return value: If length is less than 1, the str_split() function will return FALSE. If length is greater than the length of the string, the entire string is returned as the only element of the array.

php converts string to array function using:

$m='guanhui';
$arr=str_split($m);
var_dump($arr);

Output result:

array(7) {    
[0]=>    
string(1) "g"    
[1]=>    
string(1) "u"    
[2]=>    
string(1) "a"    
[3]=>    
string(1) "n"    
[4]=>    
string(1) "h"    
[5]=>    
string(1) "u"    
[6]=>    
string(1) "i"    
}

The above is the detailed content of How to convert string to array in php. 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