Split a comma-delimited string into an array? Split a comma-delimited string into an array? arrays arrays

Split a comma-delimited string into an array?


Try explode:

$myString = "9,admin@example.com,8";$myArray = explode(',', $myString);print_r($myArray);

Output :

Array(    [0] => 9    [1] => admin@example.com    [2] => 8)


$string = '9,admin@google.com,8';$array = explode(',', $string);

For more complicated situations, you may need to use preg_split.


If that string comes from a csv file, I would use fgetcsv() (or str_getcsv() if you have PHP V5.3). That will allow you to parse quoted values correctly. If it is not a csv, explode() should be the best choice.