Home  >  Article  >  Backend Development  >  How to convert comma separated array in php

How to convert comma separated array in php

藏色散人
藏色散人Original
2021-09-22 09:23:195742browse

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.

How to convert comma separated array in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn