In PHP, you can use the str_split()
function to convert a string to an array. This function splits a string into an array of characters.
Here’s an example:
$string = "Hello, world!";
$array = str_split($string);
print_r($array);
Output:
Array
(
[0] => H
[1] => e
[2] => l
[3] => l
[4] => o
[5] => ,
[6] =>
[7] => w
[8] => o
[9] => r
[10] => l
[11] => d
[12] => !
)
In this example, the str_split()
function splits the string “Hello, world!” into an array of characters, which is then printed using the print_r()
function.
Admin Changed status to publish April 2, 2023