Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP str_split() Function.
The built-in PHP str_split() function is used to convert a given string into an array.
The built-in PHP str_split() function is used to convert a given string into an array.
syntax
Following below is the syntax to use this function -
array str_split ( string $string [, int $split_length = 1 ] )
Parameter Details
Sr.No | Parameters & Description |
---|---|
1 | string It contains the information about input string |
2 | length It contains the information about length of each array |
Return Value
If the optional length parameter is specified, then the returned array will be broken down into chunks with each being length in length otherwise each chunk will be one character in length.
If length is less than one it returns false or else the entire string will be returned.
If length is less than one it returns false or else the entire string will be returned.
Example
Try out the example below -
<?php print_r(str_split("webdesigntutorialz")); ?>
Output
When the above code is executed, it will produce the following result -
Array ( [0] =>w [1] =>e [2] =>b [3] =>d [4] =>e [5] =>s [6] =>i [7] =>g [8] =>n [9] =>t [10] =>u [11] =>t [12] =>o [13] =>r [14] =>i [15] =>a [16] =>l [17] =>z )
Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we will be studying about the PHP str_word_count() Function.
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.