How to Convert String into Array in PHP?

In this blog, we will be going to understand how to convert string to array in PHP. This is going to be very simple and easy. I will explain this with examples.


Let's start with the code,


Example  1:


Code:


<?php

$myString = "Hi, I am thecodingdev.com";

$array = explode(' ', $myString);  

print_r($array);



Output:


Array


(

    [0] => Hi,

    [1] => I

    [2] => am

    [3] => thecodingdev.com

)



Example 2:


Code:


<?php

  

$myString = "Rajkot,Surat,Bhavnagar,Baroda";

$array = explode(',', $myString);

print_r($array);



Output:


Array

(

    [0] => Rajkot

    [1] => Surat

    [2] => Bhavnagar

    [3] => Baroda

)


I hope this will help you with your project. If you have any doubts, let me know in the comments.