Home >Backend Development >PHP Tutorial >How Can I Convert a Comma-Separated String into a PHP Array?
Explode a Comma-Delimited String: Array Construction
Problem:
You need to parse a comma-separated string into an individual elements within an array.
Explanation:
The explode() function provides an effective way to split strings based on a given delimiter. In this case, commas will serve as the delimiter.
Solution:
<?php $myString = "9,[email protected],8"; $myArray = explode(',', $myString); print_r($myArray); ?>
Output:
Array ( [0] => 9 [1] => [email protected] [2] => 8 )
Note that using explode() produces an array with each element representing a substring separated by the specified comma delimiter. In the provided input, the output array will contain three elements: '9', 'admin@example', and '8'.
The above is the detailed content of How Can I Convert a Comma-Separated String into a PHP Array?. For more information, please follow other related articles on the PHP Chinese website!