How to convert two-dimensional array to one-dimensional array in PHP

小云云
Release: 2023-03-22 17:22:02
Original
1987 people have browsed it

This article mainly shares with you the method of converting PHP two-dimensional array into one-dimensional array. It is mainly shared with you in the form of code. I hope it can help you.

$arr = [
    'a' => [
        1,
        2,
    ],
    'b' => [
        '3',
        '4'=>[
            '5'
        ]
    ],
    'b'
];
Copy after login
print_r(iterator_to_array(
        new RecursiveIteratorIterator(
            new RecursiveArrayIterator($arr)
        ),
        false
    )
);
Copy after login

Result:

Array ([0] => 1 [1] => 2 [2] => 3 [3] => 5 [4 ] => b )

Related recommendations:

php Convert a two-dimensional array into an array with a parent-child relationship_PHP tutorial

The above is the detailed content of How to convert two-dimensional array to one-dimensional array in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!