How can I split a comma delimited string into an array in PHP?


Question

I need to split my string input into an array at the commas.

How can I go about accomplishing this?

Input:

9,admin@example.com,8
1
236
7/14/2009 4:17:03 PM

Accepted Answer

Try explode:

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

Output :

Array
(
    [0] => 9
    [1] => admin@example.com
    [2] => 8
)
495
4/24/2016 11:49:08 AM

$myString = "9,admin@example.com,8";
$myArray = explode(',', $myString);
foreach($myArray as $my_Array){
    echo $my_Array.'<br>';  
}

Output

9
admin@example.com
8

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon