php str_split() function


  Translation results:

英[splɪt] 美[splɪt]

vt.Split;separate;<slang>(quickly) leave;share

n.divide;disagreement;crack;split

vi. Separated, split

Third person singular: splits Plural: splits Present participle: splitting Past tense: split Past participle: split

php str_split() functionsyntax

How to use the str_split() function

php The str_split() function is used to split the string into an array. The syntax is str_split(string, length). The string is divided into Divide by length to form an array.

Function: Split the string into an array

Syntax: str_split(string,length)

Parameters:

ParameterDescription
stringRequired, required Split string
length Optional, specifies the length of each array element, defaults to 1, if length is less than 1, returns false, if length length is greater than the length of the current string, the entire string will be returned as the only element of the array.

Instructions: Split the string according to the specified length to form an array

php str_split() functionexample

<?php
$i = "helloworld";
$j = str_split($i,3);//指定分割的数组元素长度为3
print_r($j); //输出数组用print_r函数
?>

Run instance»

Click the "Run instance" button to view the online instance

Output:

Array ( [0] => hel [1] => low [2] => orl [3] => d )
<?php
$i = "you can study php in php.cn";
$j = str_split($i,5);
print_r($j);
?>

Run Instance»

Click the "Run Instance" button to view the online instance

Output:

Array ( [0] => you c [1] => an st [2] => udy p [3] => hp in [4] => php. [5] => cn )

Home

Videos

Q&A