Home  >  Article  >  Backend Development  >  PHP function split

PHP function split

WBOY
WBOYOriginal
2016-07-29 08:55:382354browse

str_split() function

If the optional split_length parameter is specified, each element in the returned array is a character block of length split_length, otherwise each character block is a single character.

If split_length is less than 1, return FALSE. If the split_length argument exceeds the length of string , the entire string will be returned as only one element of the array.

$str = "Hello Friend";

$arr1 = str_split($str);
$arr2 = str_split($str, 3);

print_r($arr1);
print_r( $arr2);

?>

Output

Array
(
[0] => H
[1] => e
[2] => l
[3] => l
[4] => o
[5] =>
[6] => F
[7] => r
[8] => i
[9] => e
[10] => n
[11] => d
)

Array
(
[0] => Hel
[1] => lo
[2] => Fri
[3] => end
)


The above has introduced the PHP function split, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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
Previous article:127 error solutionNext article:127 error solution