![]() After splitting the string into smaller substrings, this function stores them in an array and returns the array.Įxplode($separator, $initial_string, $no_of_elements) Parameters This separator could be a comma (,), a dot (.), or anything. Unlike the str_split() function, this function uses a separator or delimiter that needs to be passed as an argument to the function. The explode() function is another method of PHP that is used to convert a string into an array. And the following expression passes 3 as the length delimiter, which converts the substring of length 3 into array elements. So, it converts separate elements of the string into array elements. The following expression passes the string to this method without passing the length argument.īy default, if you do not pass the length delimiter, it takes it as 1. It uses the str_split() method to convert the string to an array. In the above example, it initializes a variable $my_string1 with a string “Sample String”. Print_r($my_array2) // sam, ple, str, ing The following example illustrates the working of the str_split() function to convert string to array in PHP.Įcho "The array of length 3 elements is: " If the length that is passed to the function surpasses the length of the initial string, the function will return the whole string as one element, whereas if the length integer is less than one, the function will return false. ![]() This function returns an array that contains the pieces of the original string. If not passed, the function will consider this length as 1 by default.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |