Example
Split the string "Hello" into an array:
html
<?php
print_r(str_split("Hello"));
?>
Definition and Usage
The str_split() function splits a string into an array.
Syntax
text
str_split(string,length)
Parameter Values
| Parameter | Description |
|---|---|
| string | Required. Specifies the string to split |
| length | Optional. Specifies the length of each array element. Default is 1 |
Technical Details
| Return Value: | If length is less than 1, a ValueError will be thrown. If string is empty an empty array is returned |
|---|---|
| PHP Version: | 5+ |
More Examples
Example
Using the length parameter:
html
<?php
print_r(str_split("Hello",3));
?>