How to split comma separated string to array in PHP
In this tutorial, we are going to learn about how to split the comma-separated string into an array in PHP
Using the explode() function
We can split the comma (,
) separated string to an array by using the built-in explode()
function in PHP.
Syntax:
explode($delimiter, $string)
Here is an example, that splits the comma delimited string into an array of strings:
$user = "1,rashi,rashi@email.com";
$userArray = explode(',', $user);
print_r($userArray);
Output:
Array
(
[0] => 1
[1] => rashi
[2] => rashi@email.com
)