The str_split() is an inbuilt function in PHP and is used to convert the given string into an array. This function basically splits the given string into smaller strings of length specified by the user and stores them in an array and returns the array.
array str_split($org_string, $splitting_length)
The function accepts two parameters and are described below:
- $org_string (mandatory): This refers to the original string that the user needs to split into an array.
- $splitting_length (optional): This refers to the length of each array element, we wish to split our string into. By default the function accepts the value as 1.
Return Values: The function returns an array. If the length parameter exceeds the length of the original string, then the whole string is returned as a single element. If the length parameter is less than 1, then False is returned. By default length is equal to 1.
Input: "Hello" Output: Array (  => H  => e  => l  => l  => o )
The below program will explain the working of the str_split() function.
Array (  => G  => e  => e  => k  => s ) Array (  => Geek  => sfor  => Geek  => s )
- PHP | str_repeat() Function
- PHP | Converting string to Date and DateTime
- How to remove the first character of string in PHP?
- Insert string at specified position in PHP
- What is the use of the @ symbol in PHP?
- How to make a redirect in PHP?
- PHP | Imagick commentImage() Function
- PHP | Imagick cropImage() Function
- Difference between bindParam and bindValue in PHP
- What is the difference between the | and || or operator in php?
- What is the difference between public, private, and protected in PHP?
- How to convert an image to base64 encoding in PHP?
- Check whether a given Number is Power-Isolated or not
- Split a comma delimited string into an array in PHP
- PHP | Imagick flattenImages() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.