PHP str_split Function: Guide & Examples

The php str_split function is used to split a string into an array, with each array element containing one character. Its syntax is:

Split the given string into an array of substrings of the specified length.

Parameter description:

  1. $string: string that needs to be divided.
  2. $split_length: specifies the length of each array element, by default it is 1, meaning each element contains one character

Example: I am really looking forward to seeing you tomorrow.

$str = "Hello";
$arr = str_split($str);

print_r($arr);

The output result is:

Array
(
    [0] => H
    [1] => e
    [2] => l
    [3] => l
    [4] => o
)
bannerAds