php method to convert comma-separated arrays: 1. Create a PHP sample file; 2. Define the string that needs to be converted; 3. Use the "explode(',', $myString);" method to convert the characters The string can be converted into an array separated by commas.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to convert comma separated array to php?
Split my string input into an array at the comma
String example:
9,admin@example.com,8
The conversion method is as follows:
$myString = "9,admin@example.com,8"; $myArray = explode(',', $myString); print_r($myArray);
Output:
Array( [0] => 9 [1] => admin@example.com [2] => 8)
explode() function breaks the string into an array.
Note: The "separator" parameter cannot be an empty string.
Note: This function is binary safe.
Grammar
explode(separator,string,limit)
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to convert comma separated array in php. For more information, please follow other related articles on the PHP Chinese website!