To convert a string to an array in PHP, you can use the str_split()
function. This function splits a string into an array of characters. Here's an example:
$str = "Hello, World!";
$array = str_split($str);
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 $str
into an array of characters, and then it is printed using print_r()
to show the array elements.