How to convert string to array in php

Guanhui
Release: 2023-02-28 21:06:02
Original
5648 people have browsed it

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

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

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

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!

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