Home > Backend Development > PHP Problem > How to convert php string to array

How to convert php string to array

藏色散人
Release: 2023-03-04 22:58:01
Original
3354 people have browsed it

php string to array method: First create a PHP sample file; then use the [$arr1 = str_split($str);] method to convert the string [$str] into an array.

How to convert php string to array

Recommended: "PHP Video Tutorial"

PHP Convert string to array str_split

Convert a continuous string into a single character array

Example:

<?php
    $str = &#39;abcde&#39;;
    $arr1 = str_split($str);
    print_r($arr1);
?>
Copy after login

The output result is as follows:

Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
    [4] => e
)
Copy after login

The difference from explode is: The first parameter of explode must pass a splitting character (such as:, | space) to split; str_split splits directly

The above is the detailed content of How to convert php string to array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template