Home > Backend Development > PHP Tutorial > PHP function split

PHP function split

WBOY
Release: 2016-07-29 08:55:38
Original
2420 people have browsed it

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.

Related labels:
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