PHP str_split() Function Example | str_split() Function Tutorial
PHP str_split() is an inbuilt function that splits a string into an array. The str_split() function converts PHP string to array. The function splits the given string into smaller strings of the length specified by a user and stores them in the array and returns an array.
PHP str_split Function
The syntax of the str_split() method is following.
The string parameter is required, and it specifies the string to split.
The length parameter is optional, and it specifies the length of each array element. Default is 1.
See the following code example.
<?php print_r(str_split("Millie Bobby Brown", 6));
See the output.
➜ pro php app.php Array (  => Millie  => Bobby  => Brown ) ➜ pro
If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length; otherwise, each chunk will be one character in length.
The FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of the string, the entire string is returned as the first (and only) array element.
The str_split() will split into bytes, rather than characters when dealing with a multi-byte encoded string.
If the split_length length exceeds the length of string, the entire string is returned as the first (and only) array element.
See another example.
See the output.
➜ pro php app.php Array (  => K  => R  => U  => N  => A  => L ) ➜ pro
Finally, PHP str_split Function Example | str_split() Function In PHP is over.