How to split a comma-delimited string into an array with PHP?

Spread the love

Sometimes, we want to split a comma-delimited string into an array with PHP.

In this article, we’ll look at how to split a comma-delimited string into an array with PHP.

How to split a comma-delimited string into an array with PHP?

To split a comma-delimited string into an array with PHP, we can use the explode function.

For instance, we write

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

to call explode with ',' and $myString to split $myString by the commas into an array of substrings.

Conclusion

To split a comma-delimited string into an array with PHP, we can use the explode function.

Leave a Reply

Your email address will not be published.