How to convert a string to an array in PHP?

Today, We are going to learn How to limit string length in PHP?How to convert a string to an array in PHP?

A string is a sequence of characters in PHP. The str_split function is used to partition the string into equal lengths. Then the string part becomes an array element. The array element contains the remaining end string.

str_split() Function

The first method in this list is str_split(). This is an in-built PHP method that is used to convert a string into an array by breaking the string into smaller sub-strings of uniform length and storing them in an array.

Let’s understand with an example

<?php

$col = 'abcdefghijklmno'; 
$split = str_split($col, 4);

echo "<pre>";
 print_r($split);
echo "</pre>";

?>

OUTPUT:

Array
(
    [0] => abcd
    [1] => efgh
    [2] => ijkl
    [3] => mno
)

I hope that you found this Blog helpful. If you’ve any queries, please leave comments in the comment section.

Thanks for following and reading this blog.

gexpoundsofttechsolution