PHP: How to Convert String to an Array [explode()|str_split]. Convert String to Array using explode() explode() method is one of the built-in function in PHP which can be used to convert string to array. The explode() function splits a string based on the given delimiter. The method splits the string where the delimiter exists. Example: Convert comma separated string to array in PHP.
PHP provides various functions to convert a String to an Array. In this article, we will discuss 3 ways to convert string to array in PHP using 3 different methods:
explode() method is one of the built-in function in PHP which can be used to convert string to array.
The explode() function splits a string based on the given delimiter. A delimiter acts as a separater and the method splits the string where the delimiter exists.
Example: Convert comma separated string to array in PHP
$string = "one,two,three,four"; $arr = explode(",", $string); print_r($arr); //output Array (  => one  => two  => three  => four )
In above example, the string contains four words separated by a comma. Normally, in csv files, each column values in a row is separated by comma.
So, to extract each value and store it in array, we are converting string to array using explode() function. The returned array will contain list of words as elements.
Hire our Laravel, CodeIgniter, YII, Zend, Cake PHP, Core PHP developers for your custom web development projects. Choose best PHP Web Frameworks & get satisfactory results.
Looking to develop a PHP based website from scratch or revamp your existing website? **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")** has always been an industry leader for companies and business owners looking to hire...
![This is image title](https://telegra.ph/file/856eae74f33107c93ca2c.jpg "This is image title") Hypertext Preprocessor, commonly known as PHP, happens to be one of the most widely used server-side scripting languages for developing web...
Are you looking for a php web development company? ValueCoders is a leading software company with 16+ years of experience offering PHP website development services to global clients. 4200+ projects | 2500+ Clients| 450+ Experts.
Our dedicated PHP developers write bug-free and optimized code for custom PHP web development projects. Hire us today and get satisfactory results.