How to convert a string to array ?

Last updated 2 years, 8 months ago | 532 views 75     5

Tags:- PHP

PHP | How to convert a string to an array?

string to array

There is a function in PHP called explode() which is used to convert any string to an array. 

 
<?php

$str = "Hello world. It's a beautiful day.";

print_r (explode(" ",$str));

?>

// Output will be 
Array ( 
    [0] => Hello 
    [1] => world. 
    [2] => It's 
    [3] => a 
    [4] => beautiful 
    [5] => day. 
    )