The str_split() function is used to split a string into an array. This function was introduced in PHP5. The function splits the string into an array of characters, each containing length characters; if the length is not specified, it defaults to 1.
str_split(string $string, int $length = 1): array
|string||The input string.|
|length||Maximum length of the chunk.|
false is returned if length is less than 1. If the length length exceeds the length of string, the entire string is returned as the first (and only) array element.
<?php $text = “How are you”; $split1 = str_split($text); $split2 = str_split($text, 3); print_r($split1); print_r($split2); ?>
The output of the above program is as follows:
Array (  => H  => o  => w  =>  => a  => r  => e  =>  => y  => o  => u ) Array (  => How  => ar  => e y  => ou )