Community warning: If that string comes from a csv file, use of str_getcsv() instead is strictly advised, as suggested in this 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
)
Answer from Matthew Groves on Stack Overflow
🌐
GitHub
gist.github.com › sanikamal › 2211eb930339cb241d3b54e1e98b67d0
Convert Comma Separated String into Array in PHP · GitHub
Convert Comma Separated String into Array in PHP. GitHub Gist: instantly share code, notes, and snippets.
Discussions

how to convert comma separated string to array in array - PHP Coding Help - PHP Freaks
Hi, I need to convert comma separated values to array in array. My original string items separated with two delimiters ( | and ,). I used the following function for this purpose. function makeKeyboard($str){ $array = array(); $array = explode('|', $str); foreach($array as $key => $str) { $arra... More on forums.phpfreaks.com
🌐 forums.phpfreaks.com
October 5, 2017
php - Convert comma separated string into array - Stack Overflow
I have a comma separated string, which consists of a list of tags and want to convert it to array to get a link for every tag. Example: $string = 'html,css,php,mysql,javascript'; I want to make i... More on stackoverflow.com
🌐 stackoverflow.com
April 30, 2011
php - Array to comma separated string? - Stack Overflow
Through foreach, all array values are now comma separated. As of now, output will be test 10, test 11,. So, remove extra comma which trail in the end through rtrim(). ... Save this answer. ... Show activity on this post. There are many ways to skin this cat -- Here's one: More on stackoverflow.com
🌐 stackoverflow.com
Generate Array from a comma-separated list - PHP - Stack Overflow
The Array above works great when ... I try to use the $var in place of the comma-separated list, problems occur. So (perfect world) it could be $thePostIdArray = array($var); which would be the same as $thePostIdArray = array(1, 2, 3);. ... Thank you for any pointers. ... If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string... More on stackoverflow.com
🌐 stackoverflow.com
March 12, 2016
🌐
GeeksforGeeks
geeksforgeeks.org › php › split-a-comma-delimited-string-into-an-array-in-php
Split a comma delimited string into an array in PHP - GeeksforGeeks
July 11, 2025 - <?php // Use preg_split() function ... => 123 [1] => 46 [2] => 78 [3] => 000 ) This PHP script uses str_getcsv() to parse the comma-delimited string $string into an array, handling CSV formatting rules like quoted values with commas, ...
🌐
PHP Freaks
forums.phpfreaks.com › php coding › php coding help
how to convert comma separated string to array in array - PHP Coding Help - PHP Freaks
October 5, 2017 - Hi, I need to convert comma separated values to array in array. My original string items separated with two delimiters ( | and ,). I used the following function for this purpose. function makeKeyboard($str){ $array = array(); $array = explode('|', $str); foreach($array as $key => $str) { $arra...
🌐
CodeSpeedy
codespeedy.com › home › convert comma separated string into array in php
Convert Comma Separated String into Array in PHP - CodeSpeedy
February 23, 2020 - In the code, we use the PHP explode() function. explode function of PHP breaks a string into an array. Below is the syntax of this function: ... This is also required parameter. This string will be split into an array.
🌐
TutorialsPoint
tutorialspoint.com › article › php-program-to-split-a-given-comma-delimited-string-into-an-array-of-values
PHP program to split a given comma delimited string into an array of values
To split a given comma delimited string into an array of values, PHP provides several built-in functions like explode() and preg_split(). Both methods effectively convert a comma-separated string into an array.
🌐
Reactgo
reactgo.com › php-comma-separated-strring-to-array
How to split comma separated string to array in PHP | Reactgo
February 2, 2023 - We can split the comma (,) separated string to an array by using the built-in explode() function in PHP.
Find elsewhere
🌐
W3Docs
w3docs.com › php
How to Split a Comma Delimited String to an Array with PHP | W3Docs
The explode() function is supported on PHP 4, PHP 5, PHP 7, and PHP 8. It splits a string into an array using a specified delimiter. The function returns an array of strings, where each element is a substring created by splitting the original ...
🌐
Useful Snippets
snippets.khromov.se › home › convert comma separated values to array in php
Convert comma separated values to array in PHP - Useful Snippets
September 19, 2015 - A short snippet you can use: /** * @param $string - Input string to convert to array * @param string $separator - Separator to separate by (default: ,) * * @return array */ function comma_separated_to_array($string, $separator = ',') { //Explode ...
🌐
Joshcoast
joshcoast.com › notes › turn-a-string-into-an-array-in-php
Turn a string into an array in PHP – josh
This function splits a string by a string separator (in our case, a comma) and returns an array. ... $commaSeparatedString = "apple,banana,orange"; $array = explode(",", $commaSeparatedString); print_r($array);
🌐
CSS-Tricks
css-tricks.com › snippets › php › convert-comma-separated-string-into-array
Convert Comma Separated String into Array | CSS-Tricks
October 30, 2009 - Skip to main content · CSS-Tricks · Search · Snippets · → PHP · → Convert Comma Separated String into Array · Chris Coyier on Sep 13, 2009 Updated on Oct 30, 2009 · Easy way to turn a CSV file into a parseable array. <?php $str="foo,bar,baz,bat"; $arr=explode(",",$str); // print_r($arr); ?> Psst!
🌐
Stack Overflow
stackoverflow.com › questions › 40237263 › array-to-comma-separated-string › 40237634
php - Array to comma separated string? - Stack Overflow
Through foreach, all array values are now comma separated. As of now, output will be test 10, test 11,. So, remove extra comma which trail in the end through rtrim(). ... Save this answer. ... Show activity on this post. There are many ways to skin this cat -- Here's one: <?php $out = ''; foreach ($array as $arrayItem) { $out .= $arrayItem['b_title'] . ', '; } // Remove the extraneous ", " from the $out string...
🌐
Parthpatel
parthpatel.net › home › php › php: how to convert string to an array [explode()|str_split]
PHP: How to Convert String to an Array [explode()|str_split] | Parth Patel - a Web Developer
November 2, 2020 - Normally, in csv files, each column values in a row is separated by comma. So, to extract each value and store it in array, we are converting string to array using explode() function. The returned array will contain list of words as elements.
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-split-string-by-delimiter-separator-in-php
How to Split String by Delimiter/Separator in PHP? - GeeksforGeeks
July 23, 2025 - The explode() function in PHP splits a string into an array based on a specified delimiter. It's ideal for simple, single-character delimiters, and allows you to quickly separate string components.
🌐
Thebarton
thebarton.org › fort lauderdale seo › blog › turn a php array or object into a comma separated string
PHP array or object into a comma separated string | Florida Developer
April 20, 2016 - We can also take this a step further and turn the array keys of the associated array into a comma separated array: function to_string($data, $glue=', ', $type='field') { $output = ''; if(!empty($data) && count($data) > 0) { if($type == 'key') { $values = array_keys($data); } else { $values = array_values($data); } $output = join($glue, $values); } return $output; } $myArray = array('blue' => 'Blue', 'yellow' => 'Yellow'); $str = to_string($myArray, $type='keys'); echo $str;
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-convert-comma-separated-string-into-an-array-in-javascript.php
How to Convert Comma Separated String into an Array in JavaScript
PHP Array Functions PHP String Functions PHP File System Functions PHP Date/Time Functions PHP Calendar Functions PHP MySQLi Functions PHP Filters PHP Error Levels ... You can use the JavaScript split() method to split a string using a specific ...
🌐
GitHub
gist.github.com › jaywilliams › 385876
Convert a comma separated file into an associated array. · GitHub
I used Csvreader library but by using that I got data by exploding from comma(,) in column value. Now I got your function csv_to_array() and it solved my problem.