How to Convert a String to Array Using PHP Without Explode Function?

Hello friends, today I will tell you through this post how you convert string into string through php without using explode function. So let’s go.

convert string to array with php without explode function, change string to array by php without explode function, convert string to array in php without explode Code Example

You can convert string to array by using str_split function. How will this function be used. You are explained below with example.

str_split

The str_split function used to partition of the string into equal length. Then the string part becomes an array element. The array element contains the remaining end string.

In our example, we pass 3 to create an array whose elements have three characters each:

$string = 'abcdefghijklmnopqrstuvwxyz';
// pass 3 to split $string into an array with elements 3 characters long
$split = str_split($string, 3);
// display result using print_r
print_r($split);
/* View Source display:
Array
(
[0] => abc
[1] => def
[2] => ghi
[3] => jkl
[4] => mno
[5] => pqr
[6] => stu
[7] => vwx
[8] => yz
)
*/