Exploding a Comma-Delimited String into an Array
When working with comma-separated strings, the need to split them into individual array elements often arises.
Problem: Convert a comma-delimited string into a flat, indexed array.
Solution:
PHP provides the explode() function specifically designed for this task. It takes two arguments: a delimiter (in this case, the comma ,) and the string to be exploded.
$inputString = "9,[email protected],8"; $myArray = explode(",", $inputString); print_r($myArray);
Output:
Array ( [0] => 9 [1] => [email protected] [2] => 8 )
Note:
The above is the detailed content of How Can I Explode a Comma-Delimited String into an Array in PHP?. For more information, please follow other related articles on the PHP Chinese website!