Home > Article > Backend Development > How to use php str_split() function
In PHP, the str_split() function is used to split a string into an array, that is, convert a given string into an array, the syntax is "str_split(string, element length)". This function splits a given string into smaller strings of user-specified length, stores them in an array and returns the array.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
str_split() is a built-in function in PHP. Used to split a string into an array and convert the given string into an array. This function basically splits the given string into smaller strings of user-specified length and stores them in an array and returns the array.
Syntax
str_split(string,length)
Parameters | Description |
---|---|
string | Required. Specifies the string to be split. |
length | Optional. Specifies the length of each array element. The default is 1. |
Return value: If length is less than 1, the str_split() function will return FALSE. If length is greater than the length of the string, the entire string is returned as the only element of the array.
Example 1:
<?php $string = "Hello"; print_r(str_split($string)); ?>
Output:
Array ( [0] => H [1] => e [2] => l [3] => l [4] => o )
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to use php str_split() function. For more information, please follow other related articles on the PHP Chinese website!