- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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, the PHP code is as follows −
<?php $my_string = "456,789,23, 4, 019"; $my_str_arr = preg_split ("/,/", $my_string); print_r("The array is "); print_r($my_str_arr); $my_string = "00, 876, 5432, 1234, 0"; $my_str_arr = explode (",", $my_string); print_r("The array is "); print_r($my_str_arr); ?>
The array is Array (  => 456  => 789  => 23  => 4  => 019 ) The array is Array (  => 00  => 876  => 5432  => 1234  => 0 )
A string of numbers is defined and the ‘preg_split’ function is used to separate the numbers based on the occurance of ‘/’ or ‘.’. The split array is now printed. Another method to split the given number in the form of a string is to use the explode function. It splits the array based on the occurance of a comma.
- C# program to convert several strings into a single comma-delimited string
- Parsing a comma-delimited std::string in C++
- How to split a String into an array in Kotlin?
- MySQL select distinct rows into a comma delimited list column?
- Combining multiple rows into a comma delimited list in MySQL?
- Python program to split a string and join with comma
- PHP Pushing values into an associative array?
- PHP preg_split to split a string with specific values?
- How to split comma separated values in an R vector?
- How to split a string into elements of a string array in C#?
- How to collapse rows into a comma-delimited list with a single MySQL Query?
- Split string into sentences using regex in PHP
- Split String with Comma (,) in Java
- Program to check whether we can split a string into descending consecutive values in Python