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

How to convert comma separated array in php

藏色散人
Release: 2023-03-12 20:08:01
Original
5841 people have browsed it

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
Copy after login

The conversion method is as follows:

$myString = "9,admin@example.com,8";
$myArray = explode(',', $myString);
print_r($myArray);
Copy after login

Output:

Array(
    [0] => 9
    [1] => admin@example.com    
    [2] => 8)
Copy after login

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)
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template