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 ยท Raw ยท string_to_array.php ยท This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
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
How to convert items in array to a comma separated string in PHP? - Stack Overflow
Possible Duplicate: How to create comma separated list from array in PHP? Given this array: $tags = array('tag1','tag2','tag3','tag4','...'); How do I generate this string (using PHP): $tags = ' More on stackoverflow.com
๐ŸŒ stackoverflow.com
Convert php array into a comma separated list of strings - Stack Overflow
I have the following array: $arr = [ 0 => 'value1', 1 => 'value2', 2 => 'value3' ]; The select function of my db class takes arguments in the following format: DB::table('us... More on stackoverflow.com
๐ŸŒ stackoverflow.com
June 18, 2019
php - Convert array of comma-separated strings to a flat array of individual values - Stack Overflow
I need to change an array of comma-delimited integers into an array of individual numbers. Sample input: [ '1,24,5', '4', '88, 12, 19, 6' ] Desired result: Array ( [0] => 1 [1... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
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, ...
๐ŸŒ
CodeSpeedy
codespeedy.com โ€บ home โ€บ convert comma separated string into array in php
Convert Comma Separated String into Array in PHP - CodeSpeedy
February 23, 2020 - Now, you have seen that we have just converted a comma separated string into an array. In the code, we use the PHP explode() function. explode function of PHP breaks a 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.
๐ŸŒ
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
<?php $my_string = "apple, banana, cherry, date"; $my_str_arr = array_map('trim', explode(",", $my_string)); print_r($my_str_arr); ?> Array ( [0] => apple [1] => banana [2] => cherry [3] => date ) Use explode() for simple comma-separated strings and ...
๐ŸŒ
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 - 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...
๐ŸŒ
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 - /** * @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 on comma $vals = ...
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 ...
๐ŸŒ
Linux Hint
linuxhint.com โ€บ php-convert-array-comma-separated-string
Linux Hint โ€“ Linux Hint
Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
๐ŸŒ
CSS-Tricks
css-tricks.com โ€บ snippets โ€บ php โ€บ convert-comma-separated-string-into-array
Convert Comma Separated String into Array | CSS-Tricks
October 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! Create a DigitalOcean account and get $200 in free credit for cloud-based hosting and services. ... Is there a way to take a comma separated string like say: Tags: Something, somethingelse, thirdsomething into
๐ŸŒ
YouTube
youtube.com โ€บ watch
PHP - Turn Strings into Arrays with explode() - YouTube
Find code and diagrams at: https://www.EliTheComputerGuy.com
Published ย  May 1, 2020
๐ŸŒ
TutorialKart
tutorialkart.com โ€บ php โ€บ php-split-string-by-comma
PHP - Split String by Comma
May 7, 2023 - In this example, we will take a ... into an array of values. ... <?php $str = 'apple,banana,cherry,mango'; $values = explode(',', $str); foreach ($values as $x) { echo $x; echo '<br>'; } ?>...
๐ŸŒ
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;
๐ŸŒ
Copahost
copahost.com โ€บ home โ€บ php array to string: a complete guide
PHP Array to string: a complete guide - Copahost
July 16, 2023 - In PHP, the explode() function is used to split a string into an array of substrings based on a specified delimiter. It is commonly used when you have a string that contains multiple values separated by a specific character or sequence of ...
๐ŸŒ
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...
๐ŸŒ
Intellipaat
intellipaat.com โ€บ home โ€บ blog โ€บ converting a string to an array in php
Convert String to Array in PHP using Different Functions
August 25, 2025 - The json_decode() function takes a string argument, our JSON string, and returns a PHP array (it also has a second argument, and we are using true there, so we are getting an associative array).